我有這個問題在這裏回答bash - running remote script from local machine關於如何使用與sudo有關的遠程命令。我認爲這是工作,因爲我得到消息,我的服務器成功重新啓動等,所以我選擇了答案。但是今天我看到那臺服務器實際上沒有重啓,但因爲某種原因被殺。與sudo bash遠程命令不起作用
事情我做了,當我跑這個命令第一次:
ssh [email protected] -t 'sudo /etc/init.d/script restart' #or -t just after ssh, same thing
我得到這個消息:
Restarting openerp-server: Stopping openerp-server: openerp-server.
Starting openerp-server: openerp-server.
Connection to host.com closed.
所以,是的,當時我以爲一切都很好。但實際上會看到過程是否重新啓動,我看到它沒有工作。
當我試圖(以相同的命令)再次重新啓動,我得到這個消息:
Restarting openerp-server: Stopping openerp-server: start-stop-daemon: warning: failed to kill 25205: No such process
openerp-server.
Starting openerp-server: openerp-server.
Connection to host.com closed.
但是,如果使用相同的命令時,直接連接到遠程服務器,一切正常,我的腳本重新啓動服務器一般。 相同的命令我的意思是這樣的:
ssh [email protected]
sudo /etc/init.d/script restart
那麼到底什麼是怎麼回事?
第一個選項確實正常運行。即使退出後它也會正常重啓。但使用睡眠定時器的第二個選項解決了它。所以我猜想使用遠程命令時,重新啓動的過程需要比實際連接到服務器的時間更長。實際上,它甚至足以放置像1秒鐘的東西,並且它正常重新啓動 – Andrius 2014-09-05 09:00:18