Solved

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

Posted on 2011-02-17
8
455 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

760 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

19 Experts available now in Live!

Get 1:1 Help Now