表示 进入内容 11
Displaying posts with tag: fork (reset)
shell中的while read 与 ssh 与多线程

shell中的while read 与 ssh 与多线程

今天在写运维工具的时候,while read line之后,
再调用ssh去远程服务器上执行命令,然后while内循环只执行了一次就退出了…

cat $hostfile | while read line
do
    echo $line ":"
    ssh "$line" "w"
    echo "====" 
done

颇为不解。只好gg.
然后发现ssh会去读stdin… 我那个while read也会读stdin..父子进程读到一起去了…
man之后,发现参数-n:

      -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 example, 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 …
[获取更多]
表示 进入内容 11