Solved

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

Posted on 2011-02-17
8
456 Views
Last Modified: 2012-05-11
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
Comment
Question by:willlandymore
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 9

Expert Comment

by:AriMc
ID: 34917283
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
 
LVL 6

Expert Comment

by:Bxoz
ID: 34917291
go to the right directory en ./top.sh
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 34917305
Search top-output.txt in the $HOME directory of the user owning the crontab!

wmp
0
 
LVL 1

Author Comment

by:willlandymore
ID: 34917307
well I thought of that so I did a: locate top-output.txt but I got nothin'....
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 9

Accepted Solution

by:
AriMc earned 500 total points
ID: 34917332
The locate command does not find recently created files. Try:

find / -print | grep top-output

0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 34917341
For locate to work on new files you must run "updatedb" first. Use "find" instead!
0
 
LVL 9

Expert Comment

by:AriMc
ID: 34917364
Or simply force the location of the result file with an absolute path:

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

0
 
LVL 1

Author Comment

by:willlandymore
ID: 34917377
ooops....my bad. :)
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
problem creating new luks volume on new VM disk 5 77
Auto channel for WiFi (Access Point) 3 76
AWS vpc peering connection 1 42
route 2 traffic streams on single NIC 6 35
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now