Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Ruby and Perl Script to find all Perforce users who have not set passwords

a-script-to-find-all-users-who-have-not-set-passwords

These scripts will:
✅ Connect to the Perforce server
✅ Retrieve a list of users
✅ Identify users without passwords


1. Prerequisites

Before running the scripts, ensure:
Perforce CLI (p4) is installed and accessible in PATH
✔ You have Perforce admin privileges (needed to check user settings)
✔ You can run p4 users and p4 -ztag users successfully


2. Ruby Script: Find Perforce Users Without Passwords

#!/usr/bin/env ruby

# Define Perforce server details
P4PORT = "perforce.company.com:1666"
P4USER = "admin_user"

# Fetch list of users with details
users_output = `p4 -p #{P4PORT} -u #{P4USER} -ztag users`

# Parse the output and extract users without passwords
users_without_passwords = []

users_output.split("\n\n").each do |entry|
  user = entry.match(/^... user (\S+)/)&.captures&.first
  auth_method = entry.match(/^... AuthMethod (\S+)/)&.captures&.first || "perforce"

  # If 'AuthMethod' is missing or 'perforce', the user may not have a password set
  users_without_passwords << user if auth_method == "perforce"
end

# Print results
puts "Perforce Users Without Passwords:"
if users_without_passwords.empty?
  puts "All users have passwords set."
else
  users_without_passwords.each { |user| puts user }
end

How to Run the Ruby Script

1️⃣ Save the script as find_p4_users_without_passwords.rb
2️⃣ Replace "perforce.company.com:1666" and "admin_user" with actual Perforce server details
3️⃣ Open a terminal and run:

ruby find_p4_users_without_passwords.rb

3. Perl Script: Find Perforce Users Without Passwords

#!/usr/bin/perl
use strict;
use warnings;

# Define Perforce server details
my $P4PORT = "perforce.company.com:1666";
my $P4USER = "admin_user";

# Run 'p4 -ztag users' command and capture output
my @users_output = `p4 -p $P4PORT -u $P4USER -ztag users`;

# Parse output and extract users without passwords
my @users_without_passwords;
my $current_user;
my $auth_method = "perforce";  # Default authentication method

foreach my $line (@users_output) {
    if ($line =~ /^\.\.\. user (\S+)/) {
        $current_user = $1;
        $auth_method = "perforce";  # Reset to default for new user
    }
    elsif ($line =~ /^\.\.\. AuthMethod (\S+)/) {
        $auth_method = $1;
    }

    # If no AuthMethod or "perforce", assume no password is set
    if ($auth_method eq "perforce" && defined $current_user) {
        push @users_without_passwords, $current_user;
        $current_user = undef;  # Reset for the next user
    }
}

# Print results
print "Perforce Users Without Passwords:\n";
if (@users_without_passwords) {
    print join("\n", @users_without_passwords), "\n";
} else {
    print "All users have passwords set.\n";
}

How to Run the Perl Script

1️⃣ Save the script as find_p4_users_without_passwords.pl
2️⃣ Replace "perforce.company.com:1666" and "admin_user" with actual Perforce server details
3️⃣ Open a terminal and run:

perl find_p4_users_without_passwords.pl

4. Explanation

p4 -ztag users retrieves all Perforce users with authentication details
✔ The script extracts the AuthMethod field for each user:

  • If AuthMethod is missing or set to perforce, the user likely has no password
    ✔ The list of users without passwords is displayed

5. Conclusion

These scripts help Perforce administrators identify users who have not set passwords, improving security.

Would you like enhancements like exporting results to a file or automating password resets? Let me know! 😊

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x