shell script to get CPU, RAM usage report
Dear Linux lovers,
I need to get CPU, RAM and Disk usage report. I have executed below mentioned script from my test server. It's logging in to other server. but its providing test server details. Unable to capture other servers details. I have stored all servers hostname in test file for bala in $(cat /tmp/test) do echo "###############$bala###################" ssh $bala df -PhT | awk '{print $3,$4,$5,$7}' echo "*****************************" top -b -n1 | grep "Cpu(s)" | awk '{print $2 + $4,$5}' echo "*************************" egrep 'processor|core id' /proc/cpuinfo echo "***************" free -m echo "****************************" done >>/tmp/checklist3.txt Kindly correct me . Or else provide another bash script to get these details. Thanks Team. |
Want to add quotes around your command:
Code:
ssh $bala "df -PhT | awk '{print $3,$4,$5,$7}'" |
It will be easier to read when you wrap your script in [code] [/code] tags.
If you want all of those programs to run on the remote machine, you'll need to actually run them on the remote machine not the local host. Code:
ssh $bala "df -PhT | awk '{print $3,$4,$5,$7}'; top -b -n1 | awk '/Cpu(s)/ {print $2 + $4,$5}'; echo '*************************'; egrep 'processor|core id' /proc/cpuinfo; echo '***************'; free -m; echo '****************************';" |
It's getting error.
|
Show error.
|
Quote:
\$2, \$3, \$4 etc. It is important to note the quotes used and how they are or aren't nested. You'll need to read a bit about quoting as well. Items in single quotes are taken literally by the shell. Items within double quotes are interpreted by the shell, so items like variables must be escaped if you wish to prevent the shell from interpreting them. |
on a side note (it's what came to mind when i saw the thread title) - it's possible to use conky with CLI only.
|
Passing a script as argument bears trouble because of the local AND remote evaluation.
It is much easier to have a local checkhost.sh Code:
#!/bin/bash Code:
#!/bin/sh |
All times are GMT -5. The time now is 01:36 PM. |