Shell script Execution Conflict event-ssh&while

Source: Internet
Author: User

Today we find a problem: Read the following script: [email protected]/0 # cat ! $cat  /tmp/test_nginxls *.txt |  tr  '   '   ' \ n '  | while read linedo echo  $lineif  [  ' Yes '  ==  ' yes '  ]thenssh  192.168.109.10  ' echo  ' yes ' "elsessh  192.168.109.10  "echo  ' no '" fidone the script above is simple, read all the TXT-terminated files in the current directory (actually I just get the loop number), but we run the script to see that the script exits only once. The effect is as follows:[email protected]/0 # bash -x /tmp/test_nginx        + tr  '   '   ' \ n ' + ls 1.txt 2.txt ip.txt png.txt        + read line+ echo 1.txt1.txt+  ' ['  yes = = yes  ' + ssh 192.168.9.10  ' echo  ' ' yes ' ' yes+ read line now congratulations, You have come into contact with the ssh  and while  conflict! The approach is always more problematic. The solution is simple: Method one:  ssh  192.168.109.10  "echo  ' yes '"      changed to &NBSP; ssh  192.168.109.10  "echo  ' Yes '"   < /dev/null   method two:   ssh  192.168.109.10  "echo  ' yes '"      change to   ssh   -n 192.168.109.10  "echo  ' yes '"       causes:ssh  The command reads a loop that is not executed while the following content can help you understand it. [Email protected]/0 # bash -x /tmp/test_nginx + ls 1.txt 2.txt  ip.txt png.txt+ tr  '   '   ' \ n ' + read line+ echo 1.txt1.txt+   ' ['  yes == yes  '] ' + ssh 192.168.9.10 cat      //we change the order to cat, we'll find out. 2.txtip.txtpng.txt+ read line


This article is from the Linux system maintenance blog, so be sure to keep this source http://linuxadmin.blog.51cto.com/2683824/1885184

Shell script Execution Conflict event-ssh&while

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.