LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-09-2012, 04:19 PM   #1
wireshark11
LQ Newbie
 
Registered: Nov 2012
Posts: 6

Rep: Reputation: Disabled
Thumbs down 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
 
Old 11-09-2012, 04:22 PM   #2
wireshark11
LQ Newbie
 
Registered: Nov 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
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
 
Old 11-09-2012, 06:46 PM   #3
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
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
 
Old 11-09-2012, 06:49 PM   #4
ArfaSmif
Member
 
Registered: Oct 2008
Location: Brisbane Australia
Distribution: Fedora, Centos, Manjaro
Posts: 317

Rep: Reputation: 70
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.
 
Old 11-10-2012, 05:32 AM   #5
wireshark11
LQ Newbie
 
Registered: Nov 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
konsolebox Thanx you Very much Dude Script to cleanup log files working Amazing
 
Old 11-10-2012, 05:34 AM   #6
wireshark11
LQ Newbie
 
Registered: Nov 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
But i need help in crontab how to set to run evry 5 hours can you help me pls konsolebox
 
Old 11-10-2012, 08:45 AM   #7
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
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.

Last edited by konsolebox; 11-10-2012 at 08:55 AM. Reason: Complete suggestion change. I actually knew something.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to replace "ö" to "p" in shell scripting with "sed" meninmech Programming 5 06-22-2012 02:58 PM
[SOLVED] Shell scripting, difference of "source script.sh" and "./script.sh" Squall90 Programming 4 07-31-2010 04:40 PM
[SOLVED] Shell Scripting "syntax error : unexpected end of file" roxie600 Programming 12 04-30-2010 12:18 AM
shell scripting: "formatting" issue with text files eur0dad Programming 3 08-17-2006 10:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration