Shamsul Kamal
asked on
How to get a variable from command line using perl ?
Hi,
I would like to request an assistant.
May i know how to get the "1.53" number (variable) after the "load average :" when issuing the following command ?
eg:
root@svr17 [~]# uptime
02:28:11 up 38 days, 9:42, 2 users, load average: 1.53, 0.61, 0.63
I actually wanted to accomplish this :
if the "load" is more than "10"
{
do this
}
else {
do nothing
}
The "load" is actually the "1.53" variable get from the "uptime" command.
Appreciates if anybody can helps.
Thank you.
I would like to request an assistant.
May i know how to get the "1.53" number (variable) after the "load average :" when issuing the following command ?
eg:
root@svr17 [~]# uptime
02:28:11 up 38 days, 9:42, 2 users, load average: 1.53, 0.61, 0.63
I actually wanted to accomplish this :
if the "load" is more than "10"
{
do this
}
else {
do nothing
}
The "load" is actually the "1.53" variable get from the "uptime" command.
Appreciates if anybody can helps.
Thank you.
ASKER
Can you provide complete sample if possible based on the my requirement ?
Does this do what you want?
uptime | grep -o '[0-9]\+\.[0-9]\+*'
it should return about this:
1.53
0.61
0.63
uptime | grep -o '[0-9]\+\.[0-9]\+*'
it should return about this:
1.53
0.61
0.63
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
nordtorp, I actually wanted just "1.53" .
Vikas , you command produce error :
root@svr9 [~]# uptime | awk '{gsub("\,","");print $8}'
awk: warning: escape sequence `\,' treated as plain `,'
load
nordtorp, I actually wanted just "1.53" .
Vikas , you command produce error :
root@svr9 [~]# uptime | awk '{gsub("\,","");print $8}'
awk: warning: escape sequence `\,' treated as plain `,'
load
I don't have a linux box here so I cannot test for you, but what does this return?
uptime | grep -o '[0-9]\+\.[0-9]'
uptime | grep -o '[0-9]\+\.[0-9]'
ASKER
root@svr9 [~]# uptime | grep -o '[0-9]\+\.[0-9]'
0.8
0.8
0.7
0.8
0.8
0.7
I am sorry for just testing now, but what about this then:
uptime | grep -o -q '[0-9]\+\.[0-9]\+*'
or uptime | grep -q '[0-9]\+\.[0-9]\+*'
uptime | grep -o -q '[0-9]\+\.[0-9]\+*'
or uptime | grep -q '[0-9]\+\.[0-9]\+*'
ASKER
All is empty result :
root@svr17 [/]# uptime | grep -o -q '[0-9]\+\.[0-9]\+*'
root@svr17 [/]# uptime | grep -q '[0-9]\+\.[0-9]\+*'
root@svr17 [/]#
root@svr17 [/]# uptime | grep -o -q '[0-9]\+\.[0-9]\+*'
root@svr17 [/]# uptime | grep -q '[0-9]\+\.[0-9]\+*'
root@svr17 [/]#
ya that is just a warning that fine you can just do a echo $var to check whether it has the variable 1.53
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
it is a warning saying that you are using a escape sequence in your awk code
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks all...
http://search.cpan.org/~pioto/Unix-Uptime-0.36/lib/Unix/Uptime.pm