Visit The New, Modern Unix Linux Community

Script to send alert if any changes are made in crontab.

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to send alert if any changes are made in crontab.
# 1  
Script to send alert if any changes are made in crontab.

Hi i want to know how can i write a script to check if any changes are made and send an alert in crontabs . i am using .ksh file extension for writing scripts.
# 2  
maybe you could try something like this.
x=$(crontab -l >/tmp/crXc)
sleep 1800 #(wait for half-hour )
y=$(crontab -l >/tmp/crXy)
if [[ ! -z $(comm -3 $x $y) ]] ; then echo "crontab entry(s) is maybe changed .." ; 
echo -e "$(date "+%F %H:%M:%S") in\n --new crontab--\n`more $x` \n\nhalf an hour ago\n --old crontab--\n`more $y`"; fi
rm -f $x $y

# 3  
You could also run something like this as a root crontjob - it checks any cronttab files modified since it was last run and reports on them:

if [ -f $CKFILE ]
    find $CRONDIR -type f -newer $CKFILE | while read tabfile
       echo "Crontab file for user $(basename $tabfile) has changed" | mail -s "Crontab changed" $ALERT
touch $CKFILE

# 4  
Hi guys thanks for replying. Smilie
will try with thr scripts.

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #635
Difficulty: Medium
The iPhone 6 and 6S were available in three sizes at launch: 32, 64, and 128 GB.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to send mail alert

Hi I have below shell script to send mail alert , however I want to add more functionality in this script and that is , script should only check that file between 9 am to 5pm , and if there is no activity in this time 9 am to 5 pm for 2hours then it should give me mail alert, please help... (2 Replies)
Discussion started by: scazed
2 Replies

2. Shell Programming and Scripting

Shell script to send mail alert

HI Guys, I am writing one shell script to send the mail alert to some email id's if the file not modified in last 10 mins but its not working, I believe MTIME is null string is wrong . can you please assist me on this. script :- filename="abc.txt" echo "Filename is $filename"... (1 Reply)
Discussion started by: abhigrkist
1 Replies

3. Shell Programming and Scripting

Run a sql script on multiple $Oracle_SID at once and send an alert if reaches the threshold

I am trying to accomplish following tasks in my KSH script: Run a sql script on multiple $ORACLE_SID at once Sends an alert only if the threshold > 2 for any of the $ORACLE_SID Please advice as to how I can approach this!! Thanks in advance! (1 Reply)
Discussion started by: jd_2000
1 Replies

4. Shell Programming and Scripting

Vi : Is it possible to send ctrl + d signal from a file made with vi and executing it.

Hi Experts, Is it possible to send ctrl + d signal from a inside a file made with vi, using Ctrl V , Esc and 004 , escape sequence. Since : 004 should exit the script if executed. Is this something possible. I am trying with vi , I put this code ^ , and trying to execute it but... (4 Replies)
Discussion started by: rveri
4 Replies

5. HP-UX

Script to send alert when process exceeds 90% cpu

I have an issue with one of the processes which is showing %cpu over 120% when i issue the top command. I am looking for a script that send me an email alert when it crosses the 90% thresholds. Appreciate your help (1 Reply)
Discussion started by: chkaiban
1 Replies

6. Shell Programming and Scripting

Grep Stop status from the output of script and send an eamil alert.

Hello Team, I have script which gives below output. Server clustServer11 is in a STARTED state Server clustServer12 is in a STOPPED state Server clustServer21 is in a STOPPED state I would like to prepare script which will grep stop word from the above output and send an email alert. (5 Replies)
Discussion started by: coolguyamy
5 Replies

7. Shell Programming and Scripting

Script to send an alert if a file is present in a directory for 10 min

hi, A script which look into a directory and send an alert via a mail. If there is any file exisiting in a directory for more then 10 min. (5 Replies)
Discussion started by: madfox
5 Replies

8. Shell Programming and Scripting

How to automatically send a mail alert if the script errors out

I have a script like this, which calls other scripts from that script: #!/usr/ksh readfile=/home/sample.txt cat $readfile | while read line do file= `echo $line|awk '{print $4}'` if ; then mv $file /home/temp_stage fi (4 Replies)
Discussion started by: ss3944
4 Replies

9. Shell Programming and Scripting

Write a script to send alert for some particular hours in a day

Hi All, I have a have a script which checks for some processes whether they are running or not and if they are not running then it send a mail specifying that the processes are not running. This particular script example abc.ksh is runs in a cron like this 0,5,10,15,20,25,30,35,40,45,50,55 * * *... (5 Replies)
Discussion started by: usha rao
5 Replies

10. Solaris

Shell script to send email alert for core dump

Friends, I am in search for a shell script that is capable of running as a cronjob and have to send out an email when ever there is a CORE DUMP. Please post the hints to achieve my goal. Thanks in advance. (1 Reply)
Discussion started by: rtatineni
1 Replies

Featured Tech Videos