我的linux学习日记day6
ping
-c ping几次的意思
-i 每次的间隔
-W 最长响应时间为几秒钟
#!/bin/bash ping -c 3 -i 0.2 -W 3 $1 &>/dev/null #无论正确或者错误结果都输出到/dev/null $1 用户输入的第一个参数 if [ $? -eq 0 ] then echo "Host $1 is On-Line" else echo "Host $1 is Off-Line" fi
[root@localhost ~]# cat /tmp/while.sh #!/bin/bash PRICE=$(expr $RANDOM % 1000 ) TIMES=0 while true do read -p "Enter:" NU let TIMES++ if [ $NU -eq $PRICE ] then echo "$TIMES,Congratulations!!" exit 0 elif [ $NU -gt $PRICE ] then echo "High!!!!" else [ $NU -lt $PRICE ] echo "Low!!!" fi done
-----------------------------------------------
[root@localhost tmp]# cat user.sh #!/bin/bash read -p "Enter The passwd:" PW for USERNAME in `cat user.txt` do id $USERNAME &> /dev/null if [ $? -eq 0 ] then echo "$USERNAME,already exist" else useradd $USERNAME &>/dev/null echo "PW"|passwd --stdin $USERNAME &>/dev/null fi done
[root@system1 devops]# cat test.sh #!/bin/bash read -p "Enter:" KEY case "$KEY" in [a-z]|[A-Z]) echo "ZiMu" ;; [0-9]) echo "ShuZi" ;; *) echo "Error" esac
计划任务
用户
useradd
groupadd
用户权限
chmod 设置权限
chmod +权限 文件
chmod -权限 文件