LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   LogCleanup.sh Shell scripting problem: unexpected "fi" Any Help Pls (https://www.linuxquestions.org/questions/linux-newbie-8/logcleanup-sh-shell-scripting-problem-unexpected-fi-any-help-pls-4175436465/)

wireshark11 11-09-2012 04:19 PM

LogCleanup.sh Shell scripting problem: unexpected "fi" Any Help Pls
 
#############################################
scriptname = LogCleanup.sh
#############################################
#!/bin/sh
# Script to cleanup log files


OWNER=xxxx
TARGETDIR_1=/tmp
TARGETDIR_2=/var/cccamlog
FILE_1=warnings.txt
FILE_2=cccam.check
FILE_3=CCcam.log
FILE_4=configupdate.log

echo && date

if test -f $TARGETDIR_1/$FILE_1 ; then
echo "warning text present!"
chown $OWNER $TARGETDIR_1/$FILE_1
rm $TARGETDIR_1/$FILE_1
else
echo "No warning text present?!?!Nothing to remove"
fi

if test -f $TARGETDIR_2/$FILE_2 ; then
echo "Check File present!"
chown $OWNER $TARGETDIR_2/$FILE_2
rm $TARGETDIR_2/$FILE_2
else
echo "No Check File present?!?! Nothing to remove"
fi

if test -f $TARGETDIR_2/$FILE_3 ; then
echo "CCcam Debug Log precent!"
chown $OWNER $TARGETDIR_2/$FILE_3
rm $TARGETDIR_2/$FILE_3
else
echo "No! CCcam Debug log present, CCcam did run perfect !!"
fi

if test -f $TARGETDIR_2/$FILE_4 ; then
echo "Check File present!"
chown $OWNER $TARGETDIR_2/$FILE_4
rm $TARGETDIR_2/$FILE_4
else
echo "No Configupdate log present?!?! Nothing to remove"

fi
exit

wireshark11 11-09-2012 04:22 PM

if test -f $TARGETDIR_2/$FILE_3 ; then
echo "CCcam Debug Log precent!"
chown $OWNER $TARGETDIR_2/$FILE_3
rm $TARGETDIR_2/$FILE_3
else
echo "No! CCcam Debug log present, CCcam did run perfect !!"
fi

Not Work

konsolebox 11-09-2012 06:46 PM

I'm not sure where is the wrong part but try a cleaner or safer variation:
Code:

#!/bin/sh
# Script to cleanup log files

#############################################
# scriptname = LogCleanup.sh
#############################################

OWNER='xxxx'
TARGETDIR_1='/tmp'
TARGETDIR_2='/var/cccamlog'
FILE_1='warnings.txt'
FILE_2='cccam.check'
FILE_3='CCcam.log'
FILE_4='configupdate.log'

echo && date

if test -f "$TARGETDIR_1/$FILE_1"; then
        echo "warning text present!"
        chown "$OWNER" "$TARGETDIR_1/$FILE_1"
        rm "$TARGETDIR_1/$FILE_1"
else
        echo "No warning text present?!?!Nothing to remove"
fi

if test -f "$TARGETDIR_2/$FILE_2"; then
        echo "Check File present!"
        chown "$OWNER" "$TARGETDIR_2/$FILE_2"
        rm "$TARGETDIR_2/$FILE_2"
else
        echo "No Check File present?!?! Nothing to remove"
fi

if test -f "$TARGETDIR_2/$FILE_3"; then
        echo "CCcam Debug Log precent!"
        chown "$OWNER" "$TARGETDIR_2/$FILE_3"
        rm "$TARGETDIR_2/$FILE_3"
else
        echo "No! CCcam Debug log present, CCcam did run perfect !!"
fi

if test -f "$TARGETDIR_2/$FILE_4"; then
        echo "Check File present!"
        chown "$OWNER" "$TARGETDIR_2/$FILE_4"
        rm "$TARGETDIR_2/$FILE_4"
else
        echo "No Configupdate log present?!?! Nothing to remove"
fi

exit


ArfaSmif 11-09-2012 06:49 PM

Hello wireshark11,

I'm not going to debug your script, but I will tell you that if you put the following line

set -x

in your script at the top after the comments you will see what the script is actually doing as it works through each line.

BTW if you want scriptname = LogCleanup.sh to be a comment too, you will need to put a hash (#) in front of it too.

wireshark11 11-10-2012 05:32 AM

konsolebox Thanx you Very much Dude Script to cleanup log files working Amazing

wireshark11 11-10-2012 05:34 AM

But i need help in crontab how to set to run evry 5 hours can you help me pls konsolebox

konsolebox 11-10-2012 08:45 AM

Tutorials around the web are quite easy to understand now since the task is already common. Try one them like this one: http://www.thegeekstuff.com/2011/07/...ery-5-minutes/. If you find some things not working you could post back some details.


All times are GMT -5. The time now is 05:25 PM.