cancel
Showing results for 
Search instead for 
Did you mean: 

hwo to use cron tab

Punithan
Advisor

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
6 REPLIES
Sachin Patel
Honored Contributor

Re: hwo to use cron tab

Hi

Create script named netstat_output like

#!/bin/sh
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


Sachin
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

Hi,

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.

Cheers
~Michael~
Anyone for a Mutiny ?
Robin Wakefield
Honored Contributor

Re: hwo to use cron tab

Hi,

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.
Magdi KAMAL
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 *netActivity.sh*, 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/netActivity.sh > /home/userName/netActivity.log 2>&1


Magdi

John Carr_2
Honored Contributor

Re: hwo to use cron tab

Hi
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

cheers
John.