|
|
实例:判断输入的路径是不是一个目录123456789#!/bin/bashread -t 30 -p "Input a dir:" dirif [ -d "$dir" ]then echo "Yes,yes yes"else echo "No,no,no"fi
实例:判断apache服务是否启动12345678910111213141516#!/bin/bashtest=$(ps aux |grep httpd |grep -v grep)#定义变量test 并且查找是否启动apache的结果赋值给test#ps aux 查看当前所有正在运行的进程 #grep httpd 过滤出apache进程#grep -v grep 排除自身进程if [ -n "$test" ]then cho " $(date) httpd is ok " >> /tmp/autostart-acc.logelse systemctl start httpd.service &>/dev/null #centos7 echo " $(date) httpd is no \n httpd is autostart now" >> /tmp/autostart-err.logfi