Reputation: 13
I'm going to store last five minutes server load into a variable in a shell script. I use the following command which works perfectly:
uptime | awk -F 'load average:' '{print $2}' | awk -F', ' '{print $2}'
OUTPUT : 0.24
But when I create a shell script file it print whole uptime output.
Here is my shell script :
#!/bin/sh
uptime = $(uptime | awk -F "load average: " '{print $2}' | awk -F"," '{print $2}')
echo $uptime
OUTPUT : 19:39:22 up 52 min, 2 users, load average: 0.03, 0.12, 0.20
What is wrong in my shell script ?
Upvotes: 1
Views: 788
Reputation: 1081
Remove the extra spaces around the =
, like so:
#!/bin/sh
uptime=$(uptime | awk -F "load average: " '{print $2}' | awk -F"," '{print $2}')
echo $uptime
This worked fine for me.
Upvotes: 3