![](/img/trans.png)
[英]The ‘exit' statement in a shell script running in a Docker container exits the script but also the container; Can I prevent exiting the container?
[英]Exiting a shell script running on the host
這是我從機器1啟動到機器2的腳本代碼(遠程)
#!/bin/bash
nohup perl server.pl &
echo "script ends"
exit
文件server.pl在while(1)類型的循環中運行,永遠監聽套接字。
我現在面臨的問題是:在調用此腳本后,我將遠程啟動此Shell腳本,因此啟動該Shell腳本的文件內部還有其他工作要做。 例如:
#this script launches the shell script
$cmd = "sabkuch.sh";
$ssh->system($cmd);#using Openssh perl package to remotely run commands
#do some other processing
print "Welcome to USA\n";
運行上面的代碼時,直到給出Ctrl-C,我才能打印語句。
如果我在機器2本身上啟動此Shell腳本(而沒有從機器1遠程啟動它),則會得到理想的結果,我不知道我要去哪里錯了,這可能是什么問題?
PS:我已經注釋了shell腳本中的所有print語句(為避免某些stdout問題,盡管&導致了再次將過程帶到fg)
在Perl或SSH中這不是問題,這是使用nohup
的方式。 如果調用腳本,腳本將掛起。
ssh host2 ./sabkuch.sh
如果您這樣重定向stdout / stderr, nohup
只會真正分離以使調用ssh進程終止:
nohup perl server.pl >/dev/null 2>&1 &
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.