I have task to delete two different files from all file system. one is core file & other is old file.
i can delete core file but for old file i have to mv in different location.
i wrote a script but it is not working.
i have a two variables in this script first one is delcnt & delcnt_old.
i want to send mail if there is any value except 0 in these two variables.
like if 1st variable is having 0 and other one is 1 that mail should be trigger means
if there is any one condition it should work.
if [ $delcnt !=0 ] && [$delcnt_old != 0]
#!/bin/ksh
print '================================================'>> log_core
delcnt=0
delcnt_old=0
for files in `find ./ -name core_test -mtime -5 -type f -print`
do
echo " $files Deleted : " `date +%Y-%m-%d.%Hh%Mm%Ss` >> log_core
delcnt=$(($delcnt + 1))
/bin/rm $files
done
for oldfiles in `find ./ -name core_test_old -mtime -5 -type f -print`
do
echo " $oldfiles moved : " `date +%Y-%m-%d.%Hh%Mm%Ss` >> log_core
delcnt_old=$(($delcnt_old + 1))
/usr/bin/mv $oldfiles /usr/sap/RS2/DVEBMGS35/core_new/core_test
done
echo "deleted $delcnt files">> log_core
echo "deleted $delcnt_old files">> log_core
print '====================End==========================='>> log_core
if [ $delcnt !=0 ] && [$delcnt_old != 0]
then
cat /usr/sap/RS2/email_list | while read emails
do
echo $emails
mailx -r alert -s "Core Deletion" $emails<log_core && mailq
echo Mail Sent Successfully
done
fi
Hi,
I changed my script as you mentioned in your earlier suggestion.
but when first condition is means "delcnt" is more then 0 mail is triggered
but when 2nd condition "delcnt_old=0" is above then 0 it is not working. means second condition is not working means mail is not triggering.
kinly suggest.
#!/bin/ksh
print '================================================'>> log_core
delcnt=0
delcnt_old=0
for files in `find ./ -name core_test -mtime -5 -type f -print`
do
echo " $files Deleted : " `date +%Y-%m-%d.%Hh%Mm%Ss` >> log_core
delcnt=$(($delcnt + 1))
/bin/rm $files
done
for oldfiles in `find ./ -name core_test_old -mtime -5 -type f -print`
do
echo " $oldfiles moved : " `date +%Y-%m-%d.%Hh%Mm%Ss` >> log_core
delcnt_old=$(($delcnt_old + 1))
/usr/bin/mv $oldfiles /usr/sap/RS2/DVEBMGS35/core_new/core_test
done
echo "deleted $delcnt files">> log_core
echo "deleted $delcnt_old files">> log_core
print '====================End==========================='>> log_core
if [[ $delcnt -ne 0 && $delcnt_old -ne 0 ]];
then
cat /usr/sap/RS2/email_list | while read emails
do
echo $emails
mailx -r alert -s "Core Deletion" $emails<log_core && mailq
echo Mail Sent Successfully
done
fi rm log_core
---------- Post updated at 05:18 AM ---------- Previous update was at 03:48 AM ----------
Ofcourse, if one of the two variables are 0, it won't send email. But as i understand...you want to send email either one of the two variables are more than 1. In this case, use Or(||) not And(&&)...
if [[ $delcnt -ne 0 || $delcnt_old -ne 0 ]]
then
#bla bla
fi