LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   apachectl graceful error from cron (https://www.linuxquestions.org/questions/linux-newbie-8/apachectl-graceful-error-from-cron-922929/)

ggalan 01-09-2012 05:03 PM

apachectl graceful error from cron
 
i have a cron file that reloads apache using
Code:

RELOAD="/usr/sbin/apachectl graceful"
but in the log i get an error
Code:

(13)Permission denied: Error retrieving pid file run/httpd.pid Remove it before continuing if it is corrupted.
ive tried
Code:

RELOAD="/usr/sbin/sudo apachectl graceful"
with no luck. do i need to own a folder or give special permission somewhere?

just tried
Code:

RELOAD="sudo /usr/sbin/apachectl graceful"
and got
Code:

sudo: sorry, you must have a tty to run sudo

trbennett48 01-09-2012 06:27 PM

Two things:

- is RELOAD="/usr/sbin/apachectl graceful" the correct format for a crontab file????
I don't have Linux, but I use AIX, and its crontab file has this format:
Code:

minute  hour  day_of_month  month  weekday  command
Example for running "graceful" at 10:05 AM
Code:

05  10 * * * /usr/sbin/apachectl graceful
- Rather than trying to use "sudo"... put the graceful command in ROOT's crontab...

-tony

ggalan 01-09-2012 06:31 PM

the crontab is
Code:

0  */2  *  *  * /usr/local/bin/check.sh httpd /etc/httpd/conf.x/cronfile >> /var/log/date.log 2>&1
check.sh
Code:

#!/bin/bash

if [[ $# -ne 2 ]]
then
    echo "<*> usage: $0 <service> <target_file_to_monitor>"
    exit 0
fi

SERVICE=$1
TARGET=$2
SHORTNAME=$(basename $TARGET)
RELOAD="sudo /usr/sbin/apachectl graceful"

touch ./last_checksum_$SHORTNAME
md5sum $TARGET > ./current_checksum_$SHORTNAME
$(diff -q ./last_checksum_$SHORTNAME ./current_checksum_$SHORTNAME > /dev/null 2>&1 )
if [[ $? -eq 0 ]]
then
    echo "[*] no change `date`, week `date +"%V"`"
else
    echo "[*] $TARGET modified `date`, week `date +"%V"`"
    $RELOAD
    cp ./current_checksum_$SHORTNAME ./last_checksum_$SHORTNAME
fi


ggalan 01-09-2012 07:56 PM

think i got it
Code:

0  */2  *  *  * sudo /usr/local/bin/check.sh httpd /etc/httpd/conf.x/cronfile >> /var/log/date.log 2>&1
but had to edit
sudo nano /etc/sudoers

then add
Defaults:%USER-NAME !requiretty
Defaults:USER-NAME !requiretty


All times are GMT -5. The time now is 11:58 PM.