MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Ruby and Perl Script to find all Perforce 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
Code language: PHP (php)

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
Code language: CSS (css)

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";
}
Code language: PHP (php)

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
Code language: CSS (css)

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! ๐Ÿ˜Š

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Ruby and Perl Scripts to List Perforce Clients in Descending Access Date Order

These scripts will:โœ… Connect to the Perforce serverโœ… Retrieve a list of clients (workspaces)โœ… Sort them by last access date (descending order) 1. Prerequisites Before running the…

Read More

Perforce Interview Prep: Essential p4 Commands for Workspaces, Changelists, and Admin Tasks

A practical Perforce interview refresher focused on high-value commands and admin concepts from real usage. Learn how to query changelists, exclude files, use metadata options, and avoid risky data-removal mistakes.

Read More

Perforce Training Guide: Hands-On P4 Curriculum for Users, SCM Engineers, and Release Teams

This revised guide turns a legacy Perforce training announcement into a practical reference for planning team enablement. It summarizes the syllabus, lab workflow, core P4 command areas, and post-training adoption practices.

Read More

Perforce Tools Explained: Clients, Servers, Plug-ins, and Utilities (Legacy 2012 Reference)

This updated reference explains the Perforce tools listed in the original 2012 post, what each component does, and how they fit together. It also includes a practical p4 CLI workflow and cautions for legacy or renamed components.

Read More

How to Use `p4 duplicate` for a Perforce Branch Path Rename (Deep Rename)

When you need to move a Perforce branch path while preserving revision and integration history, `p4 duplicate` is the key command. This guide shows the workflow, exact commands, and cleanup considerations.

Read More

Perforce Changelist Numbers Explained: Default, Numbered, and Submit-Time Renumbering

Perforce changelist numbers are simple once you understand when numbers are assigned and why pending changelists can be renumbered at submit time. This guide clarifies the default changelist, numbered changelists, and practical p4 command usage.

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x