new joine need help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting new joine need help
# 1  
Old 10-28-2008
Data new joine need help

Hi all,

I am new to unix,i need all of your help in simplifying this.
i have clubed bunch of commands to zip the log files and move to a directory name with date stamp and remove the files older than 6 months....

right now i have saved this file in .sh and scheduld this to run every 30 days... it goes like this.
-------------------------------------------------------------------

NOWDATE=`date +%d%m%y`
mkdir -p /var/log/httpd/folders_log_$NOWDATE/access_log_$NOWDATE
mv /var/log/httpd/access_log.* /var/log/httpd/folders_log_$NOWDATE/access_log_$NOWDATE
mkdir /var/log/httpd/folders_log_$NOWDATE/access-ssl_log_$NOWDATE
mv /var/log/httpd/access-ssl_log.* /var/log/httpd/folders_log_$NOWDATE/access-ssl_log_$NOWDATE
mkdir /var/log/httpd/folders_log_$NOWDATE/error_log_$NOWDATE
mv /var/log/httpd/error_log.* /var/log/httpd/folders_log_$NOWDATE/error_log_$NOWDATE
mkdir /var/log/httpd/folders_log_$NOWDATE/mod_jk_$NOWDATE
mv /var/log/httpd/mod_jk.* /var/log/httpd/folders_log_$NOWDATE/mod_jk_$NOWDATE
mkdir /var/log/httpd/folders_log_$NOWDATE/ssl_request_log_$NOWDATE
mv /var/log/httpd/ssl_request_log.* /var/log/httpd/folders_log_$NOWDATE/ssl_request_log_$NOWDATE
tar -zcvf folders_log_$NOWDATE.tgz /var/log/httpd/folders_log_$NOWDATE
rm -rf /var/log/httpd/folders_log_$NOWDATE
mkdir /Folders-Log-Archival
mv /var/log/httpd/folders_log_$NOWDATE.tgz /Folders-Log-Archival
/Folders-Log-Archival/folders_log_* -mtime +180 -exec rm {} \;
--------------------------------------------------------------
please help me in simplifying this ... loking forword for help

Thanks in advance,
Vijay
# 2  
Old 10-30-2008
Most people would use logrotate to do this... any reason why you can't?

You could simplify it a little with a for loop. You also appear to be missing a find command from the last line of your script, and I have removed the unnecessary mv of the tarball:

Code:
NOWDATE=`date +%d%m%y`

for LOG in access_log access-ssl_log erro_log mod_jk ssl_request_log
do
    mkdir -p /var/log/httpd/folders_log_$NOWDATE/${LOG}_$NOWDATE
    mv /var/log/httpd/${LOG}.* /var/log/httpd/folders_log_$NOWDATE/${LOG}_$NOWDATE
done

mkdir -p /Folders-Log-Archival &&
    tar -zcvf /Folders-Log-Archival/folders_log_$NOWDATE.tgz /var/log/httpd/folders_log_$NOWDATE &&
    rm -rf /var/log/httpd/folders_log_$NOWDATE

find /Folders-Log-Archival/folders_log_* -mtime +180 -exec rm {} \;

The &&s are in there to prevent the tar and especially the rm -rf from running if the previous steps have failed, otherwise you could potentially lose some log files.
# 3  
Old 10-31-2008
hi Anni,

thanks a lot for the Help Smilie,

small doubts Smilie
(for LOG in access_log access-ssl_log erro_log mod_jk ssl_request_log)

all log generates 5 files for a month named
1)access_log
2)access_log.1
3)access_log.2
4)access_log.3
5)access_log.4

access_log file will be a active log this i cant move, and i cant stop the service to move this, i only need to move/compress rest of the files... same applies for other 4 log also

in this case what will be ur suggestion..

& iam using logrotate to just rotate the files,could u pls tell me how to compress(tgz) and move it on to diffrent server/filler

waiting for ur response....
Vijay
# 4  
Old 11-02-2008
The mv command only moves logs that end in .*, so it will only move the previously rotated logs, so it should work fine.

Have a read of man logrotate to see what it can do, specifically the compress option, and the facility for postrotate scripts, where you can add any custom processing you wish after a log is rotated.
# 5  
Old 11-03-2008
hey Dude,

Thanks for Quick Response.

i really appreciate ur help
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question