2016-12-29 50 views
0

有人在juniper swith EX系列上使用crontab嗎?我想重啓httpd作業,因爲我需要用不同的配置來運行這個過程。 我用日誌創建了一些簡單的腳本。Juniper EX交換機。 Crontab作業

#!/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" 

此外,我創建的crontab工作

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

當我運行從CMD理線輸出爲:

Go... 
changed 
Process PID: 3158 

而且一切正常,但是當我從cron運行它,然後它看起來像這樣:

Go... 
changed 
Process PID: 

我嘗試更改(添加)到crontab行:

SHELL=/bin/csh 
PATH=... 

但沒有工作。此外,我嘗試改變工作行如下所示:

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 

也許你知道我能做些什麼才能正確運行?

回答

1

我在週末解決了這個問題。當使用@reboot通過crontab運行腳本時,腳本在httpd運行之前運行,因此沒有PID。我在我的crontab行中放置了一個sleep 60,腳本延遲了60秒,運行時,httpd啓動並運行並具有PID。

這裏是我的crontab:

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

這是我的一個問題的唯一解決方案。第二個是ps到變量http_pid的傳輸結果。我一步一步地分析了腳本中的操作,結果發現查詢ps aux結果在字符串長度上僅限於80個字符。我的grep沒有檢測到字符串。我必須將ps aux更改爲ps -A(更短的版本)。 – KlapenHz