随笔分类 - shell脚本
摘要:#!/bin/bash echo "##############僵尸进程##############" check=`ps -A -o stat,ppid,pid,cmd | grep -e '^[Zz]'` if [ -n "$check" ];then echo "发现僵尸进程!" for pi
阅读全文
摘要:[root@ localhost shell]# vim useradd.sh #!/bin/bash for ((i=1;i<=5;i+1)) do cat /etc/passwd|grep user$i #查看用户是否存在、 if [ $? -eq 0 ]; then echo "用户已存在"
阅读全文
摘要:[root@ localhost shell]# vim s6.sh #!/bin/bash for i in {1..3} do read -p "请输入第${i}个数:" number${i} done echo "$number1,$number2,$number3" a=0 if [ $nu
阅读全文
摘要:[root@ localhost shell]# vim s5.sh #!/bin/bash name=`whoami` echo $name if [ $name -ne "root" ];then echo "对不起,您不是管理员" else yum -y install vsftpd fi
阅读全文
摘要:[root@ localhost shell]# touch {1..10}.txt [root@ localhost shell]# ls 10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt s1.sh s2.sh s4.sh
阅读全文
摘要:第一种方法: [root@ localhost shell]# vim s8.sh #!/bin/bash for i in `ls *.$1` do mv $i ${i%.*}.$2 done 第二种方法: [root@ localhost shell]# vim s81.sh #!/bin/ba
阅读全文
摘要:-A -A参数指定客户端的用户代理标头,即User-Agent。curl 的默认用户代理字符串是curl/[version]。 $ curl -A 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like G
阅读全文
摘要:[root@ localhost ~]# vim useradd.sh #!/bin/bash #$1 是执行脚本的第一个参数,$2 是执行脚本的第二个参数 useradd "$1" echo "$2" | passwd --stdin "$1" #执行脚本 [root@ localhost ~]#
阅读全文
摘要:[root@izbp176gmws1f6cpbllwouz ~]# vim check.sh #!/bin/bash function system(){ echo "#####################系统信息########################" OS_TYPE=`uname`
阅读全文
摘要:#!/bin/bash systemctl stop firewalld setenforce 0 user="tom" password="123" slave_ipaddr="192.168.52.34" #这里写自己从的IP地址 master_ipaddr="192.168.52.33" #这
阅读全文
摘要:AWK 1 AWK 2 3 linux取IP地址 4 5 ifconfig | grep -w inet | sed -n '1p' | awk '{print $2}' 6 7 eg: 8 9 awk -F ':' '{print $1}' /etc/passwd 10 11 awk -F ':'
阅读全文
摘要:变量分为普通变量可只读变量 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 4
阅读全文
摘要:sed 我们首先准备了一个测试文件 1. s 替换 将文件中的This替换cyy 在替换的时候如果加入了 -i 选项就会真的替换,但是只会替换每一行的第一个 -n 和 -p 一起使用表示的是打印那些发生替换的行 加入-g的参数是指全部替换,全局的一个参数 当需要从第N处替换的时候,可以加入Ng:这里
阅读全文
摘要:grep 1.-i 不区分大写小写 2.-n 区分大小写 3.-E 查找多个条件 4.-c 查找到的结果的行数 5.-w 精确查找 6.取反 7.-q 静默输出
阅读全文
摘要:1 #!/bin/bash 2 a=$(expr $RANDOM % 100) #生成一到一百的随机数 3 echo $a #打印随机数 4 b=0 5 while true 6 do 7 let b++ 8 echo "比较了第$b次!" 9 read -p "请输入一个1-100的随机数数: "
阅读全文