#!/bin/bash result=`ps -ef |grep sshd |grep -v grep|wc -l`if[$result -ge 1];thenecho sshd is running
elseecho sshd is not running
systemctl start sshd >/dev/null
fi
执行结果:
[mmrrj@localhost 0818]$ bash check_sshd.sh
sshd is running
4.检查主机是否存活,并输出结果(使用for循环实现:主机数>=2)
#!/bin/bash forhostin"$@"doping -c 2 -W 1"$host"&> /dev/null
if[$? -eq 0];thenechohost"$host" is running
elseechohost"$host" is not running
fidone
执行结果:
[mmrrj@localhost 0818]$ bash check_hosts.sh 192.168.10.1{28..30}host192.168.10.128 is running
host192.168.10.129 is not running
host192.168.10.130 is not running