- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl mongers
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
06-17-2003 11:50 PM
06-17-2003 11:50 PM
I know it can be done faster, any suggestions ?
#!/usr/local/bin/perl
#$load = `ssh 1n2 uptime`;
$load = " 9:45am up 88 days, 10:42, 9 users, load average: 0.26, 0.13, 0.13"
@load = split(/,/, $load);
$load = $load[3];
@load = split(/:/, $load);
$load = $load[1];
$load =~ s/\s+//g;
print "$load \n";
I do it this way, as I cannont get the following to work :
$load = `ssh 1n2 uptime | awk -F, '{print $3}' | awk -F: '{print $2}'`;
or
$load = `ssh 1n2 "uptime | awk -F, '{print $3}' | awk -F: '{print $2}'"`;
or
$load = `ssh 1n2 "uptime" | awk -F, '{print $3}' | awk -F: '{print $2}`;
Anyone has an idea ?
Regs David
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2003 11:59 PM
06-17-2003 11:59 PM
Re: Perl mongers
The "ssh" command returns nothing because the first "awk" pipe is incorrect - should br $4, not $3.
Try:
$load = `ssh 1n2 uptime | awk -F, '{print $4}' | awk -F: '{print $2}'`;
This should work fine.
Ollie.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2003 12:38 AM
06-18-2003 12:38 AM
Re: Perl mongers
You're awake :)
Although it's still not working :
# ./tst.pl
10:36am up 88 days, 11:33, 9 users, load average: 0.20, 0.27, 0.21
The problem is that the pipe does not work inside the quotes. I can imagine why, just not how to get around it.
Regs David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2003 12:43 AM
06-18-2003 12:43 AM
SolutionSorry, I'm half asleep!
You need to escape the '$' characters as they are interpolated in the string before being sent to the shell:
$load = `ssh 1n2 uptime | awk -F, '{print \$3}' | awk -F: '{print \$2}'`;
Hope that's better!?
Ollie.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2003 01:37 AM
06-18-2003 01:37 AM
Re: Perl mongers
$load = `ssh 1n2 uptime | awk -F, '{print \$3}' | awk -F: '{print \$2}'`;
=>
$load = (split /:/, (split /,/, `ssh 1n2 uptime`)[2])[1];
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2003 03:03 AM
06-18-2003 03:03 AM
Re: Perl mongers
Muchios gratias.
You solved quiet some issues for me right now.
Best regs David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2003 03:07 AM
06-18-2003 03:07 AM
Re: Perl mongers
For some reason I didn't get you're update, although I knew you would be able to help me out.
Thanks a lot, this indeed should solve the problem as wel plus that you help me finding the tricky split bracket solution. I've used it manyu times before, I just couldn't remember anymore how the syntax was.
Regs David