Hi,
I have a shell script what it does is
we need keep all clients monthly logs to /var/log/apache2/logs folder
Under this folder we have different clients directories.Each directory
should contain the logfiles that is access.log and error.log files for
each folder.Every month end logrotate should run and it should keep the
log files in monthnameandyear folder with monthnameandyear.tgz file.
Example:-
logfiles location /var/log/apache2/logs under this folder every client is having their folder for logs
in side that apache log files are there i.e error.log,access.log.
Every month logrotate should run and it should create a folder with monthnameandyear under this monthname folder
that perticular month logfiles .tgz file shouls be there.
ex:- /var/log/apache2/logs/bahu/may2005/may2005.log.tgz
script as follows and when i try to run this i am getting the
following error
Error
script: line 1: !/bin/sh: No such file or directory
script: line 4: syntax error near unexpected token `('
script: line 4: `set LIST = (user1 user2 user3 user4)'
Script as follows
!/bin/sh
set noclobber
set HOMEDIR = /var/log/apache2/logs
set LIST = (user1 user2 user3 user4)
set MONLIST = (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
set MONTH = `date +%m`
set YR = `date +%Y`
@ PREMON = $MONTH - 1
# Check if the previous month is December
if ($PREMON == 0) then
@ PREMON = 12
endif
# set month in name
set MONTH = $MONLIST[$PREMON]
foreach DIR ($LIST)
# set to a home directory
cd $HOMEDIR/$DIR
# creating dir
if (! -d $MONTH$YR) then
mkdir $MONTH$YR
endif
#egrep "$MONTH" access.log | egrep "$YR" > $MONTH$YR.log
#egrep "$MONTH" error.log | egrep "$YR" > error_$MONTH$YR.log
test -f access.log && mv -f
access.log $MONTH$YR.log
test -f error.log && mv -f error.log error_$MONTH$YR.log
test -f access.log || cp -f /dev/null access.log
test -f error.log || cp -f /dev/null error.log
# compressing file
tar zcvf $MONTH$YR.log.tgz $MONTH$YR.log
mv -f $MONTH$YR.log.tgz $MONTH$YR/
# removing file
rm -f $MONTH$YR.log
rm -f error_$MONTH$YR.log
end
kill -HUP `cat /var/log/apache2/logs/httpd.pid`
~
Plese help me where i am going wrong
Thanks in advance