Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 465
  • 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

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