![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Command assistance | kmuir | UNIX for Dummies Questions & Answers | 0 | 02-26-2008 07:59 PM |
| how to move word by word on command line | pbsrinivas | UNIX for Dummies Questions & Answers | 1 | 11-23-2007 02:17 AM |
| Assistance with Perl and HTTP | bryanthomas | Shell Programming and Scripting | 7 | 12-11-2006 05:38 PM |
| Can a shell script pull the first word (or nth word) off each line of a text file? | tricky | Shell Programming and Scripting | 5 | 08-17-2006 03:29 AM |
| paste command | mariner | UNIX for Advanced & Expert Users | 5 | 03-03-2005 10:42 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Perl script assistance; paste word into external command
I'm attempting to create a Perl script that will:
Take the contents of the usernames.tmp file (usernames.tmp is created from an awk one-liner ran against /etc/passwd) Take one line at a time and pass it to the su command as a users name. This should go on until there is no more name to process However there is one tiny problem, this is my first exposure to Perl scripting! And I have no idea how to do this. The code below is my full heated attempt at clobbering together code found around the office. Code:
!#/usr/bin/perl
open (USRLIST, "</tmp/usernames.tmp") || die ("die statement");
defined $USERS = (<USRLIST>);
foreach $NAME (@$USERS)
{
exec "su - $NAME;cd;/path/to/script2";
}
be a real treat!! Thanks in advance! -- -Adam B. |
| Forum Sponsor | ||
|
|
|
|||
|
Just corrected a few errors in syntax. Not sure what the result will be?
Code:
!#/usr/bin/perl
open (USRLIST, "</tmp/usernames.tmp") || die ("die statement");
@USERS = (<USRLIST>);
foreach $NAME (@USERS)
{
exec "su - $NAME;cd;/path/to/script2";
}
|
|
|||
|
Sorry, it might help if I actully state that.
The line : foreach $NAME (@USERS) Errors out with at syntax error. I'm not sure exctly what, I'll have to wait till I'm at work again to find out; when I do I'll post with the exact error. -- -Adam B. |
|
|||
|
bru,
it is likely that you wish to use system function or backquotes rather than exec. consult the documentation of exec function to know what it does. also, you forgot to close the filehandle. check if this is what you want: Code:
#!/usr/bin/perl
open (USRLIST, "< /tmp/usernames.tmp") or die ("Unable to read file /tmp/usernames.tmp : $?");
my @users = <USRLIST>;
close USRLIST or warn "Unable to close file /tmp/usernames.tmp : $?";
foreach my $user (@users) {
system ("su - $user;cd;/path/to/script2");
}
|
|||
| Google UNIX.COM |