I have written a script which will search logfiles directory particular two strings and send a message to user to kill the process id if string found every 15 minutes
Note::dont have cron tab access(Auto run every 15 minute)
oS--AIX
Please add script search the PID into logfile "My PID is: 123456" and kill that process ID
Please find the attached sample files
#!/usr/bin/ksh
while true
do
day=`date +%a`
time=`date +%H%M`
str1 = "bad Parm"
str2 = "wrong parm"
cd sri
if [ $day = "Mon" -o $day = "Tue" -o $day = "Wed" -o $day = "Thu" -o $day = "Fri" ] ;
then
if [ $time -gt 0700 -a $time -le 0900 ]; then
grep -e "$str1" -e "$str2" *.log
mail -s "Alert" "sri123@gmail.com"
else
echo "Exit successfully"
fi
done
below is the sample of
*.log file contains
Server mapping to server section and picking a place to call home...
. . . mapped . . .
. . . looking for domain . . .
. . . Found domain & got the lock; now looking for a free slot . . .
. . . looking . . .
. . . looking . . .
. . . looking . . .
. . . Found one and I'm taking it! Now let go of the lock .
* Immediate sarting . My PID is: 123456
bad parm. (GET:DATE)
bad parm. (GET:DATE)
bad parm. (GET:DATE)
date can't be a correct date
wrong parm. (NEXT.date)
wrong parm. (NEXT.date)
wrong parm. (NEXT.date)
Thanks for ur quick response i was just excuting the script output as below sorry instead of kill cmd i added echo for display pid but the script is showing else part
exit successfully but the output should be send a mail to user and display the PID
+ true
+ set = xv
date +%a
++ date +%a
+ day=Thu
date +%H%M
++ date +%H%M
+ time=1036
+ str1='bad Parm'
+ str2='wrong parm'
+ cd /home/rkd/Desktop
+ '[' Thu = Mon -o Thu = Tue -o Thu = Wed -o Thu = Thu -o Thu = Fri ']'
+ '[' 1036 -gt 0700 -a 1036 -le 0900 ']'
+ echo 'Exit successfully'
Exit successfully
+ sleep 900
OUTPUT:if it search strings any of .log files then send a alert message to users and display the pid from that logfile so that users can kill the process or script it self kill the process
1.Should it run auto without any execution and what is the extention .ksh or no need to add .ksh ?
2.should i add shebang line
What exactly are unhappy about? The time variable is 1036 and it fails the test to fall between 7:00h and 9:00h. The message given is a bit unfortunate, but the execution is as programmed - mayhap not as intended.
What do you mean by "run auto without any execution"? An extension is NOT needed.