Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 468
  • Last Modified:

running 'top' to output to a text file, from cronjob

I need to send the output of 'top' to a file but I need to run it every minute.

I am using the following command which works when run from the command line:

top -n 1 -b > top-output.txt

This gives me the file top-output.txt with the results. However, when I add:

* * * * * /root/Desktop/top.sh

and I put that command in the .sh file I made and give it +x, it doesn't seem to run.

Can anyone tell me what I'm missing?
0
willlandymore
Asked:
willlandymore
  • 3
  • 2
  • 2
  • +1
1 Solution
 
AriMcCommented:
Are you sure it is not producing the file into some other directory than where you expect?
Can you show your root's output for

   crontab -l

0
 
BxozCommented:
go to the right directory en ./top.sh
0
 
woolmilkporcCommented:
Search top-output.txt in the $HOME directory of the user owning the crontab!

wmp
0
A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

 
willlandymoreAuthor Commented:
well I thought of that so I did a: locate top-output.txt but I got nothin'....
0
 
AriMcCommented:
The locate command does not find recently created files. Try:

find / -print | grep top-output

0
 
woolmilkporcCommented:
For locate to work on new files you must run "updatedb" first. Use "find" instead!
0
 
AriMcCommented:
Or simply force the location of the result file with an absolute path:

top -n 1 -b > /root/top-output.txt

0
 
willlandymoreAuthor Commented:
ooops....my bad. :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now