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?

  • 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 2 '16 at 23:46
  • Hi,changing top -c to top -bn1 did not help either. – lionell Mar 3 '16 at 1:28
  • The 'some process name' part must not containe any % of course, unless escaped by backslash. – Ralph Rönnquist Mar 3 '16 at 1: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 3 '16 at 3:52
  • * * * * * echo $(date) + /usr/bin/top -c -d 5 -n 2|grep 'IIBD*' >> /home/abc/IIBD_output.txt – lionell Mar 3 '16 at 3:57
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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.