The Juniper EX switch. Crontab jobs

1k Views Asked by At

did someone use crontab on juniper swith EX series? I would like to do restart httpd job, because I need to run this process with different config. I create some simple script with logging.

#!/bin/csh
echo 'Go...'
cp /jail/var/etc/httpd.conf_new /jail/var/etc/httpd.conf
echo 'changed'
set http_pid=`ps aux | grep 'httpd --config' | grep -v grep | awk '{print $2}'`
echo 'Process PID: ' "$http_pid"
kill -9 "$http_pid"

Also I create a job in crontab

10 12 * * * csh /var/root/test.sh >> test.log

When I run proces from cmd then output is:

Go...
changed
Process PID: 3158

And everything is ok but when I run it from cron then it looks like that:

Go...
changed
Process PID:

I try to change(add) to the crontab line with:

SHELL=/bin/csh
PATH=...

but didn't work. Also I try to change line with job to something like below:

10 12 * * * /var/root/.profile; csh /var/root/test.sh >> test.log
10 12 * * * sh /var/root/.profile; csh /var/root/test.sh >> test.log
10 12 * * * (sh /var/root/.profile; csh /var/root/test.sh) >> test.log

Maybe you know what can I do more to run this correctly?

1

There are 1 best solutions below

1
On BEST ANSWER

I resolved this over the weekend. When the script is run via crontab using @reboot, the script runs before httpd is running, therefore there is no PID. I put a sleep 60 in my crontab line and the script delayed for 60 seconds, when it runs, httpd is up and running and has a PID.

Here is my Crontab:

@reboot sleep 60; sh /jail/var/etc/httpd_replace_config.sh > /jail/var/etc/httpd_replace_config.txt