Hi shmem
Thanks for your response it was really helpful.
I thought I would send you all my code with your suggestion attached
what is, I think is happening is its starting from the first entry in the array which is 0.
However no matter which selection I use it can’t seem to change to that user directory which does exist.
Any further help would be greatly appreciated.
#!/usr/bin/perl -w
use Cwd;
my $dir = getcwd;
my $userhome = $ENV{HOME};
my $hdir = "/export/home";
my $userlist = "/$userhome/etc/userlist.cfg";
open(MYFILE, "$userlist") || die "Cant open File $userlist: $!\n";
my @ulist=<MYFILE>;
foreach my $file (@ulist) {eval {
print "\n";
$n++;
print $n;
print " $file\n";
}}
print " Please select which user you would like to...\n";
my $number = <STDIN>;
chomp $number;
die "Invalid Selection\n" if $number =~ /\D/;
die "Number given is too big\n" if $number > scalar(@ulist);
my $user = $ulist[$number];
chdir("$hdir/$user") || die "Cant Change to directory $hdir/$user: $!\
+n";
&first;
sub first {
system("su - $user -c whatsrunning");
}
sub second {
print "Would you like to see the options again?\n";
my $answer = <STDIN>;
chomp $answer;
if ($answer eq "Y" || $answer eq "y" || $answer eq "yes") {
system("su - $user -c whatsrunning");
&second;
} else {exit 0;
}}
&second;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.