Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
We have several backup jobs running everyday. We do get mails if job is successful/fails. For some reason, if the job didnot run, we would know the status.
I am in the process of developing script for this. I have a function in my script to find waht day it is:
Here is my script:
sid1=abcd
sid2=efgh
sid3=ijkl
sid4=mnop
sid5=qrst
sid6=uvwx
if [[ dayno -eq 1 ]]
then
for i in $sid1 $sid2 $sid3 $sid4 $sid5 $sid6
do
ls $log_home/$i_level0_backup.log
if [ $? != 0 ]; then
echo "Level 0 backup for $i was not successful. Please check the log files" >> $tmpfile
echo " " >>$tmpfile
mailit=true
doneelif [[ dayno -eq 2 || dayno -eq 3 || dayno -eq 5 || dayno -eq 6 ]]
then
for i in $sid1 $sid2 $sid3 $sid4 $sid5 $sid6
do
ls $log_home/$i_level2_backup.log
if [ $? != 0 ]; then
echo "Level 2 backup for $i was not successful. Please check the log files" >> $tmpfile
echo " " >>$tmpfile
mailit=true
doneelif [[ dayno -eq 4 ]]
then
for i in $sid1 $sid2 $sid3 $sid4 $sid5 $sid6
do
ls $log_home/$i_level1_backup.log
if [ $? != 0 ]; then
echo "Level 1 backup for $i was not successful. Please check the log files" >> $tmpfile
echo " " >>$tmpfile
mailit=true
done
fiI know I am doing something wrong in 'for loop' section. I am getting syntax error.
Please help.
Thanks and Regards
Sureshsureshht

I found a number of problems:
1) In the 3 for loops, the inner if statement isn't terminated by an fi.
2) With a series of elif clauses, the terminating one must be a else with no then
3) variable dayno should have a $, but that may be optional depending on your shell.Below are the changes I made using ksh. Good hunting!
if [[ $dayno -eq 1 ]] then for i in $sid1 $sid2 $sid3 $sid4 $sid5 $sid6 do ls $log_home/$i_level0_backup.log if [ $? != 0 ]; then echo "Level 0 backup for $i was not successful. Please check the log files" >> $tmpfile echo " " >>$tmpfile mailit=true fi done elif [[ $dayno -eq 2 || $dayno -eq 3 || $dayno -eq 5 || $dayno -eq 6 ]] then for i in $sid1 $sid2 $sid3 $sid4 $sid5 $sid6 do ls $log_home/$i_level2_backup.log if [ $? != 0 ]; then echo "Level 2 backup for $i was not successful. Please check the log files" >> $tmpfile echo " " >>$tmpfile mailit=true fi done else [[ $dayno -eq 4 ]] for i in $sid1 $sid2 $sid3 $sid4 $sid5 $sid6 do ls $log_home/$i_level1_backup.log if [ $? != 0 ]; then echo "Level 1 backup for $i was not successful. Please check the log files" >> $tmpfile echo " " >>$tmpfile mailit=true fi done fi

Hi Nails,
Thanks for your response.
The 'dayno' variable without $ works for me.
The problem is : ls $log_home/$i_level1_backup.log
After $i it is not recognizing '_' (underscore).I am getting :
ls: 0653-341 The file /.log does not exist.
Thanks and regards
Sureshsureshht

Hi Nails,
Thanks for all your help.
I resolved my problem by replacing $i_level1_backup.log with ${i}_ level1_backup.logThanks and Regards
Sureshsureshht

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |