Usage: bash judge_prefix_string.sh TARGET_DIR TARGET_STR #!/bin/bash TARGET_DIR=$1 TARGET_STR=$2 ls $TARGET_DIR/$TARGET_STR* if [ $? -ne 0 ];then echo "file begin with $TARGET_STR is not existed!" else echo "file begin with $TARGET_STR is e
核心代码 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/access.log" #这里的-x 参数判断$myPath是否存在并且是否具有可执行权限 if [ ! -x "$myPath"]; then mkdir "$myPath" fi #这里的-d 参数判断$myPath是否存在 if [ ! -d "$myPath"]; then
Linux shell脚本判断网络畅通 介绍 在编写shell脚本时,有的功能需要确保服务器网络是可以上网才可以往下执行,那么此时就需要有个函数来判断服务器网络状态 我们可以通过curl来访问 www.baidu.com,从而判断服务器网络状态是否可以畅通的 网络状态判断 #!/bin/bash #检测网络链接畅通 function network() { #超时时间 local timeout=1 #目标网站 local target=www.baidu.com #获取响应状态码 local