debian hosting server logrotate shell script help with existing script - Debian

This is a discussion on debian hosting server logrotate shell script help with existing script - Debian ; 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 ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: debian hosting server logrotate shell script help with existing script

  1. debian hosting server logrotate shell script help with existing script


    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



    ---------------------------------
    Yahoo! FareChase - Search multiple travel sites in one click.

  2. Re: debian hosting server logrotate shell script help with existing script


    > script: line 1: !/bin/sh: No such file or directory


    look here

    > script: line 4: syntax error near unexpected token `('
    > script: line 4: `set LIST = (user1 user2 user3 user4)'
    >
    >
    > Script as follows
    >
    > !/bin/sh


    look here

    >
    > set noclobber

    .....

    you forgot #

    regards
    til


    --
    To UNSUBSCRIBE, email to debian-isp-REQUEST@lists.debian.org
    with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org

  3. Re: debian hosting server logrotate shell script help with existing script

    hmm please reply to the list, not to me.

    about your additional question about the syntax error in line 4:
    you should read some tutorials about (bash)scripting
    for example here:
    http://www-128.ibm.com/developerwork...y/l-bash2.html

    regards til


    --
    To UNSUBSCRIBE, email to debian-isp-REQUEST@lists.debian.org
    with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org

  4. Re: debian hosting server logrotate shell script help with existing script

    The rest of the script is in csh syntax so the first line needs to be:
    #!/bin/csh

+ Reply to Thread