Register
It is currently Sat Aug 30, 2014 10:23 am

I don't know the meaning of "IF [ -s /some_path/some_file ]"


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Wed Oct 05, 2011 4:49 am   

Joined: Wed Oct 05, 2011 4:42 am
Posts: 1
Dear users of the forum, I wish to understand this kind of syntax. Here i attach the complete procedure, which produces errors:

Code:
ERR_CODE=$?
# prende la data sysdate-4 in formato yyyy-mm-dd e la passa alla shell che zippa i log di quel giorno
DATAZ=`date --date "$dte -4 days" +"%F"`
#echo "."
echo Comprime i log del: $DATAZ
#echo "."
cd /log_appl/cdb_BTprod02
if [ -s /log_appl/cdb_BTprod02/cdb-ejb-$DATAZ*-001.log ]; then
   tar -cvf /tmp/log_$DATAZ.tar *$DATAZ*.log
   if [ "$?" -ne "0" ]; then
      echo "Errore cancellazione log della data " $DATAZ
      ERR_CODE=1
      rm -f /tmp/log_$DATAZ.tar
   else
      gzip /tmp/log_$DATAZ.tar
      mv /tmp/log_$DATAZ.tar.gz log_$DATAZ.tar.gz
      rm -f /log_appl/cdb_BTprod02/*$DATAZ*.log
   fi
else
   echo "Non esiste alcun file di log della data " $DATAZ
fi

# prende la data sysdate-22 in formato yyyy-mm-dd e la passa alla shell che elimina i log di quel giorno
DATAC=`date --date "$dte -22 days" +"%F"`
#echo "."
echo Elimina i log compressi del: $DATAC
#echo "."
cd /log_appl/cdb_BTprod02
rm -f /log_appl/cdb_BTprod02/log_$DATAC.tar.gz
if [ "$?" -ne "0" ]; then
   echo "Non esiste alcun log compresso della data " $DATAC
   ERR_CODE=2
fi

if [ "$ERR_CODE" -ne "0" ]; then
   echo "Errore procedura"
   exit $ERR_CODE
else
   exit 0
fi



Thanks a lot for your kind attention,

Have a nice day.


Top
 Profile  
 PostPosted: Wed Oct 05, 2011 11:52 am   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
You can find all parameters for the [ command (including -s) in 'man test'


Top
 Profile  
 PostPosted: Thu Oct 06, 2011 7:42 am   
User avatar

Joined: Wed Nov 17, 2010 1:02 pm
Posts: 9
Location: North Bethesda, MD
-s FILE exists and has a size greater than zero


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP