![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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 {} \;
|
|
||||
|
hi Anni,
thanks a lot for the Help small doubts ![]() (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 |
|
||||
|
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. |
![]() |
| Bookmarks |
| Tags |
| logrotate, unix commands |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|