Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

Why doesn't top command work in my script?

 
Highlighted
Honored Contributor

Why doesn't top command work in my script?

Hi All
I have a script as bellow
--
GetDate=`date +"%Y%m%d"`
LOG_NM=/home/hoanglh/report$GetDate
who -q|grep users>>$LOG_NM
sar -d 5 5 >>$LOG_NM
/usr/bin/top -h -d 1 >>$LOG_NM
Exit
---
All command above /usr/bin/top ran OK.
except /usr/bin/top command did not work?? i do not know why??? Just suspect of exit command
Have you ever experience with??
HP is simple
11 REPLIES 11
Highlighted
Honored Contributor

Re: Why doesn't top command work in my script?

use like this

export UNIX95=1;/usr/bin/top -h -n5 -d1 -f >>$LOG_NM
a warrior never quits
Highlighted
Acclaimed Contributor

Re: Why doesn't top command work in my script?

>ahsan: export UNIX95=1;/usr/bin/top -h -n5 -d1 -f >>$LOG_NM

Why would you use UNIX95? That's for ps(1).
Also, you don't want to export it:
$ UNIX95=EXTENDED_PS ps -Hfu $LOGNAME

Highlighted
Honored Contributor

Re: Why doesn't top command work in my script?

its a old unix command like statement

anyway nguyen you can just ignore the export .
a warrior never quits
Highlighted
Honored Contributor

Re: Why doesn't top command work in my script?

Sorry, for further deviating from the thread's topic.
But apart from the useless use of UNIX95 in top context,
setting it as suggested (i.e. along with the false trailing semicolon) is utterly wrong, insofar as a set environment variable will change the behavior of all XPG4 aware commands for the pending shell with possibly escaping the notice of the shell's user.
So the recommended usage of this environment variable is in fact as Dennis has demonstrated so that it only effects the command immediately issued.
Madness, thy name is system administration
Highlighted
Acclaimed Contributor

Re: Why doesn't top command work in my script?

Hi:

To add to your answer. Using 'top' without the '-f filename' switch and argument (as you did) tells 'top' to add terminal-formatting codes to its output stream. This renders the redirected output in your logfile rather useless.

You want:

# top -h -d 1 -f ${LOG_NM}

Notice that NO redirection is used. 'top' will append to the file used as the argument of '-f'.

Regards!

...JRF...
Highlighted
Honored Contributor

Re: Why doesn't top command work in my script?

Thank you all.
I do not want to export UNIX95 because it effects to my environment.
I changed my script as
UNIX95=1;/usr/bin/top -h -d 1 >>$LOG_NM
but it still did not works.
Hi ahsan, Ralph do you have any ideas???
I will changes my script as
/usr/bin/top -h -d -f $LOG_NM
I will rely the result soon
thank for your help
HP is simple
Highlighted
Honored Contributor

Re: Why doesn't top command work in my script?

> UNIX95=1;/usr/bin/top -h -d 1 >>$LOG_NM
> but it still did not works.

Remove UNIX95 completely from your script. It has no meaning here.

> I will changes my script as
> /usr/bin/top -h -d -f $LOG_NM

This will work just fine. top was not originally designed as a script program but instead manipulates your terminal window. So the -f option in top turns off this special handling.


Bill Hassell, sysadmin
Acclaimed Contributor

Re: Why doesn't top command work in my script?

Hi (again) Nquyen:

Read again my post, above.

> I will changes my script as
/usr/bin/top -h -d -f $LOG_NM

That will not work, you need:

I will changes my script as
/usr/bin/top -h -d1 -f $LOG_NM

...or a least a non-zero argument following the '-d' switch.

Regards!

...JRF...


Highlighted
Honored Contributor

Re: Why doesn't top command work in my script?

Hi all
I change my script as:
===
GetDate=`date +"%Y%m%d"`
LOG_NM=/home/hoanglh/report$GetDate
who -q|grep users>>$LOG_NM
sar -d 5 5 >>$LOG_NM
/usr/bin/top -h â d1 -f $LOG_NM
==
But top command doesn't works.
Please help me to point out why
Point has been assigned to acknowledge your support
HP is simple