If you don't mind, lets do a little code review which will solve your problem and help you write better code.
The first thing I noticed is that you're probably not using the strict pragma. I base that on some of your vars not being declared with the 'my' keyword. If you are using the strict pragma, then your code tells me that you're declaring some of those vars in the wrong place.
Code:
@ypcat_cmd_users =(`ypcat passwd.byname | cut -f1 -d: | sort -n`);
Lets look at this from right to left. Since you're loading the data into a hash, which is an unordered list, using sort in the command doesn't make any sense.
Using cut to select the desired fields is fine, but you're also using split in the foreach loop and doing both of those doesn't make any sense. My preference would be to drop the pipe to cut and handle it with split.
Code:
@words = split /s+/, $line;
$username = $words [0];
Did you rally mean to split on the literal 's' character? Or did you mean to split on \s whitespace? In either case, it doesn't make any sense in this case.
Var names should describe or convey some meaning about the contents of the var. @words doesn't tell you anything about the data it holds. The $username var does tell you what kind of data it holds and should have been used instead of the unneeded @words var.
Code:
foreach my $u (keys %users) {
A single letter var $u doesn't convey any meaning of the contents. You should use $user or $usr.
Code:
if ( $u eq "bb" || $u eq "tech1" || $u eq "hpsmh" || $u eq "testact") {
Rather than using multiple alternation tests, it would be cleaner and more efficient to use a hash lookup for the usernames that you want to skip. The alternation approach doesn't scale well.
Doing that var assignment doesn't make any sense. Just have a simple next; statement.
Code:
@df_cmd = (`df -k ~$u`);
The parens are unneeded.
Code:
if ($line =~ /^rusehf0b.corp.utcitar.us:/.*/home_(.*)/) {
You're using the wrong quantifier. You should be using + instead of *.
Your indentation in the code blocks is inconsistent.
Putting all that together gives you this:
Code:
#Extracts NIS Userids
my %users;
my @nis_users = `ypcat passwd`;
foreach my $line (@nis_users) {
my ($username, $pass) = split /:/, $line;
next if $pass eq '!';
$users{$username}++;
}
my %skip = (
bb => 1,
tech1 => 1,
hpsmh => 1,
testact => 1,
);
# Run df command on each user
foreach my $user (keys %users) {
next if exists $skip{$user};
@df_cmd = `df -k ~$user`;
foreach my $line (@df_cmd) {
if ($line =~ /^rusehf0b.corp.utcitar.us:/.+/home_(.+)/) {
$users {$u} = 0;
}
}
}