Operating System - Linux
1752767 Members
5223 Online
108789 Solutions
New Discussion юеВ

Why doesn't top command work in my script?

 
Nguyen Anh Tien
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
Jeeshan
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
Dennis Handly
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

Jeeshan
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
Ralph Grothe
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
James R. Ferguson
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...
Nguyen Anh Tien
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
Bill Hassell
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
James R. Ferguson
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...


Nguyen Anh Tien
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