Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Showing results for 
Search instead for 
Did you mean: 

hwo to use cron tab


hwo to use cron tab

hello now i got to get the report of netstat -s
for every 30 minit .
now hwo to to it using n cron tab and swave it in one folder
System Engineer
Sachin Patel
Honored Contributor

Re: hwo to use cron tab


Create script named netstat_output like

cd /home/sachin
day=`date +%d`
host=`uname -n`

netstat -s >> ${host}.${day}

sendmail -s "output of netstat -s" sachin < ${host}.${day}
exit 0

This will create a one file per day.
then first run it from command line to check how does it works.

add that to crontab
#crontab -e
0,30 * * * * * /home/sachin/netstat_output

Is photography a hobby or another way to spend $
Tom Danzig
Honored Contributor

Re: hwo to use cron tab

Or simply:

0,30 * * * * netstat -s >> /tmp/netstat.out
Michael Tully
Honored Contributor

Re: hwo to use cron tab


Just one piece of advice in regards to the use of crontab. Never use the -e option, I've seen on a number of occassions where the crontab file has been lost.

# crontab -l >/tmp/wrk1
Make your changes
# crontab -l /tmp/wrk1

This will ensure your original is always in tact.

Anyone for a Mutiny ?
Robin Wakefield
Honored Contributor

Re: hwo to use cron tab


I get cron to back itself up, then you only lose a day's changes at most, should something go wrong:

00 00 * * * /usr/bin/crontab -l > /usr/local/etc/crontab

Rgds, Robin.
Respected Contributor

Re: hwo to use cron tab

Hi Punithan,

First create your script and Second insert it and redirect standard input and Standard error to a log file.

1. First :
Your script will be called **, located in /home/userName and will look like the following three lines :

echo "-=> Start log on `hostname` at `date` : "
/usr/bin/netstat -n
echo "-=> End log on `hostname` at `date` : "

2. Second :
Entry in crontab and redirecting standard Input/Output to the log file called *netActivity.log* located in /home/userName, each 30 minutes :

0,30 * * * /home/userName/ > /home/userName/netActivity.log 2>&1


John Carr_2
Honored Contributor

Re: hwo to use cron tab

not the answer to the question but an alternative way to do crontab .I simply make a copy of the crontab file and then edit the original with vi then issue crontab crontab_filename.

crontab files are found in /usr/spool/cron/crontabs