- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: call system command and store result in variab...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2005 06:40 AM
07-11-2005 06:40 AM
call system command and store result in variable
print "Enter ID of user to modify: "; $mod =
$REC = `grep ^$mod /etc/passwd`;
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2005 06:53 AM
07-11-2005 06:53 AM
Re: call system command and store result in variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2005 06:53 AM
07-11-2005 06:53 AM
Re: call system command and store result in variable
Your specific problem is that you need to strip your linefeed.
$mod =
chomp($mod);
You should also note that grep w/o -E doesn't understand "^" so lose the "^".
Finally, you should note that you might match more than one so you would be better served by assigning to an array but you would be far better served by writing this whole thing in Perl.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2005 07:01 AM
07-11-2005 07:01 AM
Re: call system command and store result in variable
Trying to put together a shell-driven menu that allows end user to add/modify/delete a user from /etc/passwd without ever having to touch that file.
I'll attach what I have thus far, so you guys can have a good laugh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2005 10:45 PM
07-11-2005 10:45 PM
Re: call system command and store result in variable
I you want to search a string in a file use fgrep in place of grep.
I hope it help
Roland
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2005 01:12 AM
07-12-2005 01:12 AM
Re: call system command and store result in variable
print "Enter ID of user to modify: "; $mod =
chomp($mod);
$passwd = "/etc/passwd";
open(PW,$passwd) or die "Can't open $passwd:$!\n";
while (
($name,$passwd,$uid,$gid,$gcos,$dir,$shell) = split(/:/);
if (${mod} eq ${name}) {
print "${name} has the following values\n\n";
print "Password is: \t${passwd}\n";
print "User ID: \t${uid}\n";
print "Group ID: \t${gid}\n";
print "User name: \t${gcos}\n";
print "Home Directory: ${dir}\n";
print "Default shell: ${shell}\n";
system "/usr/bin/sleep 2";
&MainMenu;
}
elsif (${mod} ne ${name}) {
next;
}
}
close(PW); #Does it go here.
print "${mod} not found in /etc/passwd\n";
system "/usr/bin/sleep 2";
&MainMenu;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2005 01:33 AM
07-12-2005 01:33 AM
Re: call system command and store result in variable
Also don't use the curly braces around Perl variables --- Perl ain't shell.
print "Enter ID of user to modify: ";
$mod =
print "\n\n";
chomp($mod);
($name,$passwd,$uid,$gid,$quota,$comment,$gecos,$dir,$shell) = getpwnam($mod);
if (defined($name))
{
print "Okay\n"
}
else
{
print "User ",$mod," not found."
}
It would be a good idea to "man perlfunc | lp" to get a listing of the available functions.