I'm trying to write a script to calculate the usage of Log Archive in a directory, so if it gets to a point where the directory size is 60%, then send out an FYI.. email. So if then it reaches to 80%, move the logs from that directory.
I have written the script as follow but I'm getting errors. Your help is really needed and appreciated!
Script:
#!/bin/csh
set OUTPUTLOG="$HOME/logs/Log_Archive/ORA_Log_Archive.log"
set DATE=`date`
echo "--------------------------------------------------------" >> $OUTPUTLOG
echo "Log_Archive script started at $DATE" >> $OUTPUTLOG
echo "--------------------------------------------------------" >> $OUTPUTLOG
set HOST=`hostname`
set DATE=`date +"%m"-"%d"-"%Y"_"%H":"%M"`
set NUMARCHLOGS=`ls $HOME/xyz | wc -l`
set LOG_ARCH_PERCENT=`df -m $HOME/xyz | grep -v "Filesystem" | awk '{print int(substr($4,0,length($4)-1))}'`
#
echo "There are $NUMARCHLOGS Logs in $HOME/xyz >> $OUTPUTLOG
if ($LOG_ARCH_PERCENT > 60) then
echo "Log_Arive since it's at $LOG_ARCH_PERCENT" >> $OUTPUTLOG
mail -s "Subject:Log Archive is at $LOG_ARCH_PERCENT% on $HOST" xyz@xyz.com
endif
if ($LOG_ARCH_PERCENT > 80) then
mv $HOME/xyz/* $HOME/xyzbackup >> $OUTPUTLOG
echo "Moving Log_Arive since it's at $LOG_ARCH_PERCENT" >> $OUTPUTLOG
mail -s "Subject:Log Archive is moved to a xyzbackup on $HOST" xyz@xyz.com
endif
I did try this before, however, it gave me the following error
Error:
@NUMARCHLOGS=10: Command not found.
if: Expression Syntax.
I'm still getting this error even after using "[]" syntax. I have cut down the script as follow. Can you please help me to figure out where the problem would be?
Script:
set OUTPUTLOG="$HOME/logs/Log_Archive/ORA_Log_Archive.log"
set DATE=`date`
echo "--------------------------------------------------------" >> $OUTPUTLOG
echo "Log_Archive script started at $DATE" >> $OUTPUTLOG
echo "--------------------------------------------------------" >> $OUTPUTLOG
set HOST=`hostname`
set DATE=`date +"%m"-"%d"-"%Y"_"%H":"%M"`
@NUMARCHLOGS=`ls $HOME/LOG | wc -l`
set LOG_ARCH_PERCENT="df -m $HOME/LOG | grep -v "Filesystem" | awk '{print int(substr($4,0,length($4)-1))}'"
#
if [ $LOG_ARCH_PERCENT -gt 80 ]; then
echo "Moving Log_Arive since its at $LOG_ARCH_PERCENT" >> $OUTPUTLOG
mv $HOME/LOG/* $HOME/backup/archive >> $OUTPUTLOG
mail -s "Subject:Log Archive is moved to a xyzbackup on $HOST" syz@abc.com< $OUTPUTLOG
endif
Thanks for the help. I have tried the following commands/sysntaxes but getting the same issues.
if [[ $LOG_ARCH_PERCENT -gt "60" ]]; then
if [[ $LOG_ARCH_PERCENT -ge "60" ]]; then
if [ $LOG_ARCH_PERCENT -gt "60" ]; then
if [ $LOG_ARCH_PERCENT -ge 60 ]; then
if [[ $LOG_ARCH_PERCENT -gt `60` ]]; then
if [[ $LOG_ARCH_PERCENT -ge `60` ]]; then
I agree. The problem is the missing double quote. I had missed that the script was using csh (and the missing quote). The if () syntax is correct for csh.