Using of Top command as script parameter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using of Top command as script parameter
# 1  
Old 12-27-2006
Using of Top command as script parameter

Hi All

I am interested at using the output of Top command which shows some important system paramter related to CPU usage. I want to write a shell script in order to manipulate this output of command and to take some statistics for CPU.

Basically, I tried to redirect the top output to a textfile in this way:

Top > test

Except the fact the this action lasted too much, the content of filled new file was misformatted, where rows where mixed with eachother.

I have tried the same thing on a SUSE Linux machine and it worked.
I dont know why here it doesnt work in order to have a formatted content in the file.

Is there any solution for this? And besides the redirection method (top > test) is there any other method to create a file with the top output?

Thanks and Best Regards
Elthox
# 2  
Old 12-27-2006
Don't know if your version of top has this, but HP-UX does:
Code:
top -f filename

# 3  
Old 01-31-2007
Hi Again..

I`m trying to use the output of Top command as an input for one of my scripts especially to find out the cpu load which is changeable in every second. So all I want to do is to wait for some seconds the generated output of Top and then retrieve it. Up to now I couldnt find anything and doing only this top > file gives me only the output of first appearence in screen.

Please could anyone help me on this topic if its possible
# 4  
Old 01-31-2007
If you specify iterations with -n count , and delay with -d seconds , does it print multiple iterations to the file? For more detail on these options see man top .

If not, running top multiple times would be one obvious way to get output from multiple runs.
# 5  
Old 01-31-2007
Its pretty easy to use Sar when computing CPU usage than top in the scripts.

Go through sar man pages. Am sure, it will fill the gap.

Cheers, Murli.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Passing shell script parameter value to awk command in side the script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff |... (1 Reply)
Discussion started by: Sarita Behera
1 Replies

2. Post Here to Contact Site Administrators and Moderators

Unable to pass shell script parameter value to awk command in side the same script

Variable I have in my shell script diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk -F'~' ''$2 == "$id"' {print $0}' > $new I could see value of $id is not passing to the awk... (0 Replies)
Discussion started by: Ashunayak
0 Replies

3. Shell Programming and Scripting

Passing parameter to script, and split the parameter

i am passing input parameter 'one_two' to the script , the script output should display the result as below one_1two one_2two one_3two if then echo " Usage : <$0> <DATABASE> " exit 0 else for DB in 1 2 3 do DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}` done fi (5 Replies)
Discussion started by: only4satish
5 Replies

4. Shell Programming and Scripting

Command that takes one parameter and then searches for the passed in parameter

Hi I am looking for a unix command or a small shell script which can takes one parameter and then searches for the passed in the parameter in any or all files under say /home/dev/ Can anyone please help me on this? (3 Replies)
Discussion started by: pankaj80
3 Replies

5. Shell Programming and Scripting

Shell Script to grep output from top command.

Hello, I want a script which would grep details from top command for specific processes. I m not sure of the PID of these processes but i know the names. $ top -c top - 16:41:55 up 160 days, 5:53, 2 users, load average: 9.36, 9.18, 8.98 Tasks: 288 total, 9 running, 279 sleeping, 0... (8 Replies)
Discussion started by: Siddheshk
8 Replies

6. Shell Programming and Scripting

perl script - command line parameter

i am a beginner, i want to make a program that takes any command line arguments... and print it out in reverse. ie. if the command line argument is "thanks for helping me" i want it to output "me helping for thanks" :D i have tried using the reverse command, but i cant get it working!! ... (3 Replies)
Discussion started by: bshell_1214
3 Replies

7. Shell Programming and Scripting

Parsing a command line parameter in script

I have a simple script that builds a complex program call which passes a number of parameters to the program. I'm trying to enhance the script to include the value of the command line parameter in the name of a file being created. The problem I'm having is that the parameter may include a forward... (11 Replies)
Discussion started by: pbmax626
11 Replies

8. Shell Programming and Scripting

Need help with shell script - output of top command

I have written shell script to send file as an attachemt of email and output of "top -o res" command as email body. it works fine if i execute manually from prompt but it does not send "top -o res" command output in email body when it is executed via crontab. Any suggestions. My script is below:... (5 Replies)
Discussion started by: needyourhelp10
5 Replies

9. AIX

Top command in AIX 4.2 (no topas, no nmon, no top)?

Is there a 'top' command equivalent in AIX 4.2 ? I already checked and I do not see the following ones anywhere: top nmon topas (1 Reply)
Discussion started by: Browser_ice
1 Replies

10. UNIX for Advanced & Expert Users

How to kill top command using script?

Hi all, I am using top command in my script to redirect output to temp file. I used kill -9 `ps -ef|grep top|grep -v grep|awk '{print $2}'` to kill top command in my script, but it is not working? Can you please tell how to kill top command in my script? (4 Replies)
Discussion started by: johnl
4 Replies
Login or Register to Ask a Question