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
Solved

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

Posted on 2011-02-17
8
458 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
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 
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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

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

Suggested Solutions

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
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.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

839 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