Bitbull Tech Notes - home of free minds ...

Why SSH is breaking bash loops and how to get around

[root@kvm2 bin]# seq 3 | while read i; do echo $i; done
1
2
3
[root@kvm2 bin]# seq 3 | while read i; do echo $i ; ssh kvm1 date ; done
1
Wed Sep 13 15:55:46 CEST 2017
[root@kvm2 bin]# for i in $(seq 3) ; do echo $i ; ssh kvm1 date ; done
1
Wed Sep 13 15:55:54 CEST 2017
2
Wed Sep 13 15:55:54 CEST 2017
3
Wed Sep 13 15:55:54 CEST 2017
[root@kvm2 bin]# for i in $(seq 3) ; do echo $i ; ssh -n kvm1 date ; done
1
Wed Sep 13 15:56:03 CEST 2017
2
Wed Sep 13 15:56:04 CEST 2017
3
Wed Sep 13 15:56:04 CEST 2017

file2wiki bash function

Hi there

If you often have to write system documentations in mediawiki, you will love this bash function:

file2wiki(){
if [ $# -gt 1 ] ; then
   for f in $*
   do
      file2wiki $f
   done
fi

f=$1
echo "<div class=\"toccolours mw-collapsible mw-collapsed\" style=\"width:60%\">
File: <b>$1</b>
<div class=\"mw-collapsible-content\">
<pre>"
cat $1
echo "</pre>
</div>
</div>
"
}

 

usage example:

file2wiki /etc/motd /etc/sysconfig/iptables /etc/sysconfig/network-scripts/ifcfg-eth* /etc/sysconfig/network-scripts/route-eth* /var/spool/cron/* /usr/local/sbin/*

 

 

Home