Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Logrotate.d for every httpd instance for loop?

Shell Programming and Scripting


Tags
shell script, solved

Closed    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 03-08-2016   -   Original Discussion by xgringo
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is online now Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 23 April 2018, 5:17 AM EDT
Location: Simplicity
Posts: 4,037
Thanks: 346
Thanked 1,358 Times in 1,224 Posts
The following makes sense (to me)


Code:
for instance in /apps/apache/*httpd*
do
  if [ -d "$instance" ] && [ ! -f /etc/logrotate.d/"$instance" ] && service "$instance" status >/dev/null 2>&1
  then
    sed "s|examplehost|$instance|g" </usr/local/scripts/examplelogconfig >/etc/logrotate.d/"$instance"
  fi
done

I don't know what the /usr/local/scripts/stage/ is for; you can add a cp command in the loop block if needed.
Sponsored Links
    #9  
Old Unix and Linux 03-09-2016   -   Original Discussion by xgringo
xgringo's Unix or Linux Image
xgringo xgringo is offline
Registered User
 
Join Date: Dec 2006
Last Activity: 9 April 2018, 2:56 PM EDT
Posts: 53
Thanks: 1
Thanked 0 Times in 0 Posts


Code:
ls -d /apps/apache/*httpd* | while read -r name
do	if [ ! -f "/apps/apache/$name" ]
	then	cp /usr/local/scripts/examplescript.txt /usr/local/scripts/stage/ \
        sed 's|examplehost|$name|g' /usr/local/scripts/stage/$name > "/usr/local/scripts/stage/$name"
	fi
done

I tried to change what you started not quite working for me.

---------- Post updated at 01:06 PM ---------- Previous update was at 01:04 PM ----------

Ok one min I didn't see this last post....

---------- Post updated at 01:09 PM ---------- Previous update was at 01:06 PM ----------

I think this should work



Code:
for instance in /apps/apache/*httpd*
do
  if [ -d "$instance" ] && [ ! -f /etc/logrotate.d/"$instance" ] && service "$instance" status >/dev/null 2>&1
  then
    sed "s|examplehost|$instance|g" </usr/local/scripts/examplelogconfig >/usr/local/scripts/stage/"$instance"
  fi
done

I have to copy them into /usr/local/scripts/stage/ before I can later move them to /etc/logrotate.d/ during non production hours etc.

---------- Post updated at 01:19 PM ---------- Previous update was at 01:09 PM ----------

My output is this from running that....


Code:
>I removed /dev/null 2>&1

/apps/apache/httpd-cibcbeta: unrecognized service
/apps/apache/httpd-cibctrain: unrecognized service
/apps/apache/httpd-fundsdev: unrecognized service
/apps/apache/httpd-fundstrain: unrecognized service
/apps/apache/httpd-mlidev: unrecognized service
/apps/apache/httpd-mliqat: unrecognized service
/apps/apache/httpd-mlitrain: unrecognized service
/apps/apache/httpd-mliuat: unrecognized service

---------- Post updated at 01:30 PM ---------- Previous update was at 01:19 PM ----------

and if I remove

Code:
&& service "$instance" status >/dev/null 2>&1

Then I get...



Code:
./logrot.sh: line 8: /usr/local/scripts/stage//apps/apache/httpd-cibcbeta: No such file or directory
./logrot.sh: line 8: /usr/local/scripts/stage//apps/apache/httpd-cibctrain: No such file or directory
./logrot.sh: line 8: /usr/local/scripts/stage//apps/apache/httpd-fakedir: No such file or directory
./logrot.sh: line 8: /usr/local/scripts/stage//apps/apache/httpd-fundsdev: No such file or directory
./logrot.sh: line 8: /usr/local/scripts/stage//apps/apache/httpd-fundstrain: No such file or directory
./logrot.sh: line 8: /usr/local/scripts/stage//apps/apache/httpd-mlidev: No such file or directory
./logrot.sh: line 8: /usr/local/scripts/stage//apps/apache/httpd-mliqat: No such file or directory
./logrot.sh: line 8: /usr/local/scripts/stage//apps/apache/httpd-mlitrain: No such file or directory
./logrot.sh: line 8: /usr/local/scripts/stage//apps/apache/httpd-mliuat: No such file or directory

Sponsored Links
    #10  
Old Unix and Linux 03-09-2016   -   Original Discussion by xgringo
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is online now Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 23 April 2018, 5:17 AM EDT
Location: Simplicity
Posts: 4,037
Thanks: 346
Thanked 1,358 Times in 1,224 Posts
My bad, $instance needs to be the short file name.


Code:
if cd /apps/apache
then
  for instance in *httpd*
  do
    if [ -d "$instance" ] && [ ! -f /etc/logrotate.d/"$instance" ] && service "$instance" status >/dev/null 2>&1
    then
      sed "s|examplehost|$instance|g" </usr/local/scripts/examplelogconfig >/usr/local/scripts/stage/"$instance"
    fi
  done
fi

BTW the staging only makes sense for testing, i.e. if there is no test system.
I would rather let the script directly copy to /etc/logrotate.d/, and run the script at the desired maintenance slot.

Last edited by MadeInGermany; 03-09-2016 at 05:05 PM..
    #11  
Old Unix and Linux 03-16-2016   -   Original Discussion by xgringo
xgringo's Unix or Linux Image
xgringo xgringo is offline
Registered User
 
Join Date: Dec 2006
Last Activity: 9 April 2018, 2:56 PM EDT
Posts: 53
Thanks: 1
Thanked 0 Times in 0 Posts
I'm still getting

when I removed /dev/null 2>&1

I get several of these errors

/apps/apache/httpd-fakedir: unrecognized service
Sponsored Links
    #12  
Old Unix and Linux 03-16-2016   -   Original Discussion by xgringo
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is online now Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 23 April 2018, 5:17 AM EDT
Location: Simplicity
Posts: 4,037
Thanks: 346
Thanked 1,358 Times in 1,224 Posts
In my last script there is


Code:
  for instance in *httpd*

So $instance becomes the short name httpd-fakedir not the pathname /apps/apache/httpd-fakedir
The Following User Says Thank You to MadeInGermany For This Useful Post:
xgringo (03-16-2016)
Sponsored Links
    #13  
Old Unix and Linux 03-16-2016   -   Original Discussion by xgringo
xgringo's Unix or Linux Image
xgringo xgringo is offline
Registered User
 
Join Date: Dec 2006
Last Activity: 9 April 2018, 2:56 PM EDT
Posts: 53
Thanks: 1
Thanked 0 Times in 0 Posts
I understand that but it's not copying the file over to the directory and then doing the sed statement it just gives me the unrecognized
Sponsored Links
    #14  
Old Unix and Linux 03-16-2016   -   Original Discussion by xgringo
Chubler_XL's Unix or Linux Image
Chubler_XL Chubler_XL is offline Forum Staff  
Moderator
 
Join Date: Oct 2010
Last Activity: 18 April 2018, 9:54 PM EDT
Posts: 3,512
Thanks: 154
Thanked 1,249 Times in 1,145 Posts
Can you just have 1 log rotate that does them all?



Code:
/apps/apache/*/logs/*log {
    rotate 7
    compress
    missingok
    notifempty
    sharedscripts
    daily
    delaycompress
    nomail
    postrotate
          SERV=${1#*apache/}
          SERV=${SERV%%/*}
          /sbin/service $SERV reload > /dev/null 2>/dev/null || true
    endscript
}

Edit: I can see sharedscripts would cause an issue here (would only reload the last SERVER rotated)
if you don't mind restarting everything after it's done you could just use /usr/bin/killall -HUP httpd in the postrotate:




Code:
/apps/apache/*/logs/*log {
    rotate 7
    compress
    missingok
    notifempty
    sharedscripts
    daily
    delaycompress
    nomail
    postrotate
        /usr/bin/killall -HUP httpd
    endscript
}


Last edited by Chubler_XL; 03-16-2016 at 06:30 PM..
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Logrotate - /etc/logrotate.conf does't exist snchaudhari2 AIX 2 06-21-2013 01:27 PM
Logrotate - I am not able to rotate files using logrotate VSom007 Shell Programming and Scripting 5 04-15-2013 02:23 PM
logrotate httpd logfiles renuka Red Hat 1 01-11-2010 10:25 AM
logrotate with /etc/logrotate.conf file skmdu UNIX for Advanced & Expert Users 2 10-17-2009 07:04 AM
[PHP] endless loop mimics a cron. Make sure only one instance is running jjshell Shell Programming and Scripting 2 12-24-2008 11:00 AM



All times are GMT -4. The time now is 05:22 AM.