run script error

General support questions including new installations
Post Reply
sub320
Posts: 23
Joined: 2016/01/21 15:57:05

run script error

Post by sub320 » 2016/01/31 15:13:46

I have a script as below

Code: Select all

if [[ ... ]] ; then
top
fi
it works fine , when run it , it run "top" command on the foreground.

Now , I wold like to run the command "top" in background , it changed the script to as below , it pops the error "top: failed tty get" , would advise what is wrong , how to fix it . thanks .

Code: Select all

if [[ ... ]] ; then
top &
fi

aks
Posts: 3073
Joined: 2014/09/20 11:22:14

Re: run script error

Post by aks » 2016/01/31 18:53:14

Top accepts input from the keybaord so it needs a tty.
So don't do that, what are you trying to achieve?

sub320
Posts: 23
Joined: 2016/01/21 15:57:05

Re: run script error

Post by sub320 » 2016/02/01 15:40:21

thanks reply ,

what I just want is use the process of running the command "top" in background to eating up system resource , this is only testing purpose , is there any way to make it work ?

thanks

aks
Posts: 3073
Joined: 2014/09/20 11:22:14

Re: run script error

Post by aks » 2016/02/01 18:03:38

Possibly. I think you might be better off with dstat (at least you could parse it's output) or something like that.
If you just want a general overview (like CPU utilisation, memory consumed, I/O etc.) what not just use sar?

gerald_clark
Posts: 10642
Joined: 2005/08/05 15:19:54
Location: Northern Illinois, USA

Re: run script error

Post by gerald_clark » 2016/02/08 22:22:00

man top
Look at the -b, -d, and -n options.

Post Reply