The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 09-01-2007
kamitsin's Avatar
kamitsin kamitsin is offline
Registered User
 

Join Date: Nov 2006
Location: /dev/null
Posts: 177
Quote:
check=`ls|grep cc3|wc -l` #This will not work always because if a file exists with cc3 it will count that file also, what you need is the files with extension cc3.

if [ $check -ne 0 ] # if file exists the value of $check will not be null
then
echo "INPUT FILE NOT FOUND FOR TODAY................................" > $LOG_DIR/errorperry.log # it should be file found
echo " " >> $LOG_DIR/errorperry.log
echo " " >> $LOG_DIR/errorperry.log
echo "Please verify the reason for the FAILURE....................." >>$LOG_DIR/errorperry.log
echo " " >> $LOG_DIR/errorperry.log
echo " " >> $LOG_DIR/errorperry.log
echo "EXITING FROM PROCESS..............................................................." >>$LOG_DIR/errorperry.log
cd $LOG_DIR
cat /disk1/stonehs1/log/perry/errorperry.log|mailx -s "ALERT-NO FILE FOUND" `cat maillist`
exit 1
else
echo "INPUT FILE FOUND FOR TODAY...................................." >> $LOG_DIR/perry.log
echo " " >> $LOG_DIR/perry.log
echo "NUMBER OF RECORDS IN INPUT FILE STarts.............................." >> $LOG_DIR/perry.log
echo " " >> $LOG_DIR/perry.log
echo " " >> $LOG_DIR/perry.log
wc -l *.cc3 >> $LOG_DIR/perry.log
echo " " >> $LOG_DIR/perry.log
echo " " >> $LOG_DIR/perry.log
echo " " >> $LOG_DIR/perry.log
cat /disk1/stonehs1/log/perry/perry.log|mailx -s "ALERT-FILE FOUND" `cat maillist`
exit 0
1) if unmatched - i am assuming that you have missed it while pasting the script.

2) problem with conditional statement logic.

if $check is not equal to zero then the file exists else does not exist.
You have put it otherway round so even if the file exist you will get the message file does not exist.

make it

Code:
if [[ $check -eq 0 ]]
or reverse the statements if the condition is true.

3) you would have been able to check the error yourself with the value of $check because you always had the debugging on in the script.

Cheers,
K
Reply With Quote