Solved

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

Posted on 2011-02-17
8
460 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Turn your laptop into a mobile console!

The CV211 Laptop USB Console Adapter provides a direct Laptop-to-Computer connection for fast and easy remote desktop access with no software to install.

 
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
 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

696 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