The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-28-2008
vijaygowda vijaygowda is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
Unhappy 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 (permalink)  
Old 10-30-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
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 (permalink)  
Old 10-31-2008
vijaygowda vijaygowda is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
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
  #4 (permalink)  
Old 11-02-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
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 (permalink)  
Old 11-03-2008
vijaygowda vijaygowda is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
hey Dude,

Thanks for Quick Response.

i really appreciate ur help
Closed Thread

Bookmarks

Tags
logrotate, unix commands

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:50 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0