管理遠程服務器時 不可避免的使用while ,但是當在while下執行循環時 ssh會中斷 ,用for執行就不會出現這種問題
解決辦法有兩個
1.用for循環替代 while循環
2. 用while循環時 ,ssh 增加 -n參數
man ssh
-n Redirects stdin from /dev/null (actually, prevents reading from stdin). This must be used when ssh is
run in the background. A common trick is to use this to run X11 programs on a remote machine. For exam-
ple, ssh -n shadows.cs.hut.fi emacs & will start an emacs on shadows.cs.hut.fi, and the X11 connection
will be automatically forwarded over an encrypted channel. The ssh program will be put in the back-
ground. (This does not work if ssh needs to ask for a password or passphrase; see also the -f option.)