通常作为一个应用程序的部署脚本,開始的第一项工作是为当前应用创建一个专用(dedicated)的用户和用户组.这个脚本非常easy.这里贴一个參考样本: #!/bin/sh user=test_user group=test_group #create group if not exists egrep "^$group" /etc/group >& /dev/null if [ $? -ne 0 ] then groupadd $group fi #create use
Linux shell脚本判断网络畅通 介绍 在编写shell脚本时,有的功能需要确保服务器网络是可以上网才可以往下执行,那么此时就需要有个函数来判断服务器网络状态 我们可以通过curl来访问 www.baidu.com,从而判断服务器网络状态是否可以畅通的 网络状态判断 #!/bin/bash #检测网络链接畅通 function network() { #超时时间 local timeout=1 #目标网站 local target=www.baidu.com #获取响应状态码 local
在脚本中,判断执行者是否为root. 判断方法1, #!/bin/bash if [ `whoami` != "root" ];then echo " only root can run me" exit fi 判断方法2(但是用sudo执行回报脚本有语法错误,不知为何,有知道的高手请回复我). ];then echo "you are root" fi
#输入:固定格式的用户数据user.sql #处理:循环读取user.sql中的每行(每行对应一条用户数据),依次调用curl命令将用户插入BearyChat #输出:执行结果输出到日志文件outlog.txt #版本:V1. num= for line in `cat errorData.sql` do #截断 IFS=',' arr=($line) #body参数赋值 domainid=${arr[]}; domainname=${arr[]}; username=${arr[]}; use
1.判断变量 read -p "input a word :" word if [ ! -n "$word" ] ;then echo "you have not input a word!" else echo "the word you input is $word" fi 2.判断输入参数 #!/bin/bash if [ ! -n "$1" ] ;then echo "you have n