Script to run (log) top command after every few minutes using crontab (CPU utilization logs)

#!/bin/sh
top -b -n 1 | head -17 >> /var/log/logging.txt
echo “=========” >> /var/log/logging.txt

Change the permissions to execute:
chmod 777 script1

Put a shell script in one of these folders: /etc/cron.daily, /etc/cron.hourly, /etc/cron.monthly or /etc/cron.weekly

If these are not enough for you, you can add more specific tasks eg. twice a month or every 5 minutes or… go to the terminal and type:

crontab -e

this will open your personal crontab (cron configuration file), so use http://crontab-generator.org/ to generate the crontab line and paste it under the file.

Advertisements

Posted on June 11, 2015, in Linux (Ubuntu/CentOS). Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: