LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-10-2010, 01:24 AM   #1
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 229

Rep: Reputation: 18
bash scripting help


I have written a script to detect access.log.1.gz file in my log directory /var/log/squid/
the problem i am facing is that when i run this script the squid service stops. i think the reason for this is that the current file access.log.1 is in ram is being read.

in my log directory i sometimes get access.log.1.gz, acess.log.2.gz and so on, can someone tell me a better way to do detect only the gz files which are rotated and move them to a desired directory without affecting the squid working

thanks a lot the script is given below

#!/bin/bash
cd /var/log/squid
YMD="`date +%d%b%y`"
echo "------------------------------------------------" >> ~/squid_script/log
echo -e "backup of squid logs on $YMD\n" >> ~/squid_script/log
echo "------------------------------------------------" >> ~/squid_script/log
for file in a*.gz
do
echo -e "renamed file $file to $file$YMD " >> ~/squid_script/log
mv $file /media/backup/access/$file$YMD
echo -e "file $file$YMD transfered to /media/backup/access/ \n" >> ~/squid_script/log
done
 
Old 05-10-2010, 01:29 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
So just to confirm, you are saying that once the file has been zipped it is no longer in use?
 
Old 05-10-2010, 01:33 AM   #3
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 229

Original Poster
Rep: Reputation: 18
yes once compressed then of no use to squid , i have to move it to another directory where i can analyze the logs
 
Old 05-10-2010, 02:16 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
So does - ~/squid_script/log
Only contain "*gz" files?

If so, I would be guessing, but it is perhaps stopping due to the zipping not being completed at time of transfer and hence it is actually still
connected to squid who then loses connection and dies. The only test that springs to mind would be to test the size of the zipped file and once it has stopped growing
then moving it.
 
Old 05-10-2010, 02:57 AM   #5
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 229

Original Poster
Rep: Reputation: 18
I think you are not following me.

~/squid_script/log it generates a log of the transfer ">>" redirects the output into the file called "log"
the configuration file /etc/logrotate.conf generates the gz file once a week ie on sunday i run the above script at midnight on monday, so i dont think its the problem of compression
after the access.log.1.gz is formed the system automatically creates a new access.log file

i think that during the transfer this file too is read which causes the problem
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash scripting ZAMO Linux - General 1 12-04-2008 03:53 AM
Reading a bash variable in bash scripting problem freeindy Programming 3 11-27-2008 03:29 AM
Bash scripting disruptive Programming 5 06-29-2006 04:49 PM
Bash scripting JonCooperUK Programming 3 03-04-2004 09:55 PM
need help with bash scripting rich2oo1 Programming 2 12-17-2003 01:50 PM


All times are GMT -5. The time now is 03:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration