![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help in wrting Load Script for a Load-Resume type of load. | ankitgupta | Shell Programming and Scripting | 1 | 11-09-2006 09:46 PM |
| Library won't load | sansan | UNIX for Dummies Questions & Answers | 0 | 11-06-2006 01:42 AM |
| could not load hme | nikk | UNIX for Advanced & Expert Users | 1 | 12-20-2004 09:12 PM |
| NFS Load | malcom | UNIX for Advanced & Expert Users | 1 | 06-03-2004 07:39 AM |
| when i try to load Redhat 7.2 | ASpin | Filesystems, Disks and Memory | 2 | 11-13-2002 03:36 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
How to find the load on CPU ?
Hi ALL,
I have to develop a script which checks for the load on CPU on regular intervals. I created a simple script which uses 'uptime' command to find out the avg load in the last 5 min. I then used grep and put the value of the avg load in a variable OUT. It was working fine till now. Now I have to build one more condition wherein if the load is above 5 then I have to find out the top processes which are consuming the resources. I tried the following if [ "$OUT" -gt "$THRESHOLD" ] then top -n 1 > top$$.lst fi But this is not working since OUT is a character variable and if condition is expecting it to be integer. Please help me out. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
OUT=`uptime|cut -d"," -f6|cut -d"." -f1`
THRESHOLD="5" if [ "$OUT" -gt "$THRESHOLD" ] then echo "Below are the TOP 5 processes" ps -eo pcpu,pid,user,args | sort -r|grep -v "%CPU"|head -5 else echo "CPU under control" fi |
|
#3
|
|||
|
|||
|
Thanks for your reply.
But the problem is not solved. Here is the script .... #!/bin/ksh OUT1=`date | awk '{print $1" "$2" "$3" "$4" "}'` TIME=`date +%H:%M` OUT2=`uptime | awk '{print $8}' | sed 's/\,//g'` OUT=`uptime|cut -d"," -f6|cut -d"." -f1` echo $OUT2 THRESHOLD="5" if [ "$OUT" -gt "$THRESHOLD" ] then top -n 1 > top$TIME fi and when I run it following it errors out with following : -bash: [: : integer expression expected Any Clues ?? |
|
#4
|
|||
|
|||
|
if ur using the bash shell change ksh to bash...
|
|
#5
|
|||
|
|||
|
I did the change ... but it didnt help ...
|
|
#6
|
|||
|
|||
|
have u been try this?
if [ "$OUT" > "$THRESHOLD" ] |
|||
| Google The UNIX and Linux Forums |