[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2011-02-17
8
Medium Priority
?
464 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
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 several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.
Suggested Courses

650 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