#!/bin/bashself=192.168.10.128
name=mmrrj
forhostin192.168.10.{127..132}doping -c 2 -W 1"$host"&> /dev/null
if[$? -eq 0];thenechohost"$host" is running
if[$host!=$self]thenecho"ifconfig |grep inet "|ssh$name@$hostfielseechohost"$host" is not running
fidone
执行结果:
[mmrrj@localhost 4day]$ bash ping_and_ssh.sh
host192.168.10.127 is not running
host192.168.10.128 is running
host192.168.10.129 is not running
host192.168.10.130 is not running
host192.168.10.131 is running
Pseudo-terminal will not be allocated because stdin is not a terminal.
client_global_hostkeys_private_confirm: server gave bad signature for RSA key 0: error in libcrypto
Activate the web console with: systemctl enable --now cockpit.socket
inet 192.168.10.131 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:fecf:6e6d prefixlen 64 scopeid 0x20<link>
inet6 fe80::21f1:7d4b:d0d2:74cd prefixlen 64 scopeid 0x20<link>
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
host192.168.10.132 is not running
[mmrrj@localhost 4day]$
#!/bin/bashecho"-----exec+while-----"exec<filewhileread line
doecho"$line"doneecho"-----管道符+while"catfile|whileread line
doecho"$line"doneecho"-----重定向+while"whileread line
doecho"$line"done<file
执行结果:
[mmrrj@localhost 4day]$ bash read_file.sh
-----exec+while-----
this
is
a
file
-----管道符+while
this
is
a
file
-----重定向+while
this
is
a
file