0

I have a text file topcommand.txt which has a command as below:

* * * * * /usr/bin/top -c | grep 'some process name' >> /home/abcd/topout.txt

When I invoke this using crontab topcommand.txt, file topout.txt gets created but it is an empty file.

Is there something wrong with my top command?

techraf
  • 5,831
  • 10
  • 33
  • 51
lionell
  • 1
  • 2
  • please change the `top -c` part of your line with `top -bn1` and see if it helps you. With `-c` option, you are toggling the last known state of operational mode and it might give you a different behavior every time. – MelBurslan Mar 02 '16 at 23:46
  • Hi,changing top -c to top -bn1 did not help either. – lionell Mar 03 '16 at 01:28
  • The `'some process name'` part must not containe any `%` of course, unless escaped by backslash. – Ralph Rönnquist Mar 03 '16 at 01:41
  • That's correct the process name does not contain %, below is the actual command that i used. * * * * * echo $(date) + /usr/bin/top -c -d 5 -n 2|grep 'IIBD*' >> /home/n997736/IIBD_output.txt | AWK '{PRINT $0, "\n"}' – lionell Mar 03 '16 at 03:52
  • * * * * * echo $(date) + /usr/bin/top -c -d 5 -n 2|grep 'IIBD*' >> /home/abc/IIBD_output.txt – lionell Mar 03 '16 at 03:57
  • That was the actual command. – lionell Mar 03 '16 at 03:58
  • * * * * * /usr/bin/top -c -d 5 -n 2 >> /home/n997736/IIBD_output.txt 2>&1 That command writes a warning message to the file -TERM environment variable not set. When i do an echo for the variable i see the variable is set.********iibd1:~> echo $TERM xterm – lionell Mar 03 '16 at 05:13

1 Answers1

0

You should try the following

* * * * * /usr/bin/top -c | grep 'some process name' >> /home/abcd/topout.txt 2>&1

You can find some explanation here:

http://www.unix.com/solaris/207049-help-what-does-2-1-do-crontab.html

What does '>/dev/null 2>&1' mean in this article of crontab basics?

olibiaz
  • 101
  • 3