1.按照时间生成文件2018-05-22.log
将每天的磁盘使用状态写入到对应日期的文件
统计Nginx日志中每个IP的访问量有多少,日志如下:
192.168.56.1 - - [21/May/2018:20:44:06 -0400] "GET /index.html HTTP/1.0" 404 169 "-" "ApacheBench/2.3" "-"/code/index.html
awk '{print $1}' nginx.txt |sort|uniq -c|sort -r >>/access.log
[root@alice scripts]# cat jisuanqi.sh
#!/bin/bash
read -p "please input two number: " n1 n2
expr $n1 + 1 >/dev/null 2>&1
[ $? -ne 0 ] && echo "请输入两个整数" && exit
expr $n2 + 1 >/dev/null 2>&1
[ $? -ne 0 ] && echo "请输入两个整数" && exit
echo "$n1+$n2=`awk "BEGIN{print $n1+$n2}"` "
echo "$n1-$n2=`awk "BEGIN{print $n1-$n2}"` "
echo "$n1*$n2=`awk "BEGIN{print $n1*$n2}"` "
echo "$n1/$n2=`awk "BEGIN{print $n1/$n2}"` "
sed -n 1,5p passwd |sed '/[a-zA-Z]/d'
sed -n 6,10p passwd |sed 's#[a-zA-Z]##g'
sed 6,10's#[a-zA-Z]##g' passwd |sed '/[a-zA-Z]/d^C
[root@alice scripts]# cat 2.4.sh
#!/bin/bash
for i in I am lizhenya teacher I am 18
do
[ ${#i} -lt 5 ] && echo "$i"
done
[root@alice scripts]# vim 2.5.sh
#!/bin/bash
# Author: dang kai
# Blog: www.dkaiyun.com
# Time: 2019-03-18 19:50:27
# Name: 2.4.sh
# Version: 4.2.46
# Description: This is a Script.
sum=0
for i in `awk -F: '{print $3}' /etc/passwd`
do
[ $i -ge 1000 ] && sum=$[$sum+1]
done
[ $sum -eq 0 ] && echo "当前系统无普通用户"
[ $sum -gt 0 ] && echo "当前系统普通用户数量为:$sum"
[root@alice scripts]# cat 2.6.sh
#!/bin/bash
# Author: dang kai
# Blog: www.dkaiyun.com
# Time: 2019-03-18 20:45:28
# Name: 2.6.sh
# Version: 4.2.46
# Description: This is a Script.
echo "此用户最常用命令TOP10: "
echo "使用次数 命令"
awk '{print $1}' /root/.bash_history |sort|uniq -c |sort -nr|head
[root@alice scripts]# cat 2.7.sh
#!/bin/bash
# Author: dang kai
# Blog: www.dkaiyun.com
# Time: 2019-03-18 20:59:53
# Name: 2.7.sh
# Version: 4.2.46
# Description: This is a Script.
for i in `seq 3 3 100`
do
sum=$[ $sum+$i ]
done
echo "$sum"
或者
seq 3 3 100 |tr '\n' '+'|sed -r 's#(.*)#\10\n#g'|bc
test -f /etc/hosts
if [ $? = 0 ]
then
echo !
fi
for i in ` seq 1 254 `
do
{
ping -c 1 -w 1 223.5.5.$i &>/dev/null
if [ $? -eq 0 ]
then
echo " 223.5.5.$i 是在线的"
fi
}&
done
the squid project provides a number of resources toassist users design,implement and support squid installations. Please browsethe documentation and support sections for more information
3.1 按单词出现频率降序排序!
echo "the squid project provides a number of resources toassist users design
implement and support squid installations. Please browsethe documentation and
support sections for more infomation" |grep -o '[a-zA-Z]'|sort|uniq -c|sort -nr|
head
3.2 按字母出现频率降序排序
echo "the squid project provides a number of resources toassist users design
implement and support squid installations. Please browsethe documentation and
support sections for more infomation" |sed 's#[,.]##g'|xargs -n1|sort|uniq -c
sort -nr
ps aux |grep test.sh|grep -v grep|awk '{print $2}'|xargs kill -9
num=`echo $((RANDOM%100+1))`
while true
do
read -p "请输入一个数字: " an
expr $an + 1 &>/dev/null
if [ $? -eq 0 ]
then
let i++
[ $an -gt $num ] && echo "您输入的数大了" && continue
[ $an -lt $num ] && echo "您输入的数小了" && continue
[ $an -eq $num ] && echo "您猜对了" && break
fi
done
echo "您一共猜了 $i 次"
hangshu=`cat passwd |wc -l`
for i in `seq $hangshu `
do
lenth=`sed -n "$i"p passwd |sed s#[^0-9]##g|wc -L`
if
[[ $lenth = 1 ]]
then
sed -n "$i"p passwd
fi
done
#! /bin/bash
read -p “请输入网站名称: ” web
curl -sI web |awk 'NR==1{print $2}'
if [ $web = 200 ]
then
echo “正常”
else
echo “异常”
fi
i=0
while [ $i -le 100 ]
do
sum=$[ $sum+$i ]
let i++
done
echo $sum
disk=`df -h |awk 'NR==2 {print $(NF-1)}'`
if [ ${disk%\%} -ge 80 ]
then
echo " `date` 当前硬盘使用率为: $disk " >>/var/log/disk.err
fi
read -p "请输入用户名前缀: " qian
[ -z $qian ] && echo "前缀不能为空! " && exit
read -p "请输入需要创建的用户数量: " shu
[[ ! $shu =~ ^[0-9]+$ ]] && echo "请输入一个整数" && exit
echo "创建数量: $shu "
for i in `seq $shu`
do
useradd $qian$i
done
tail /etc/passwd
#!/bin/bash
# Author: dang kai
# Blog: www.dkaiyun.com
# Time: 2019-03-20 11:59:58
# Name: nginx.sh
# Version: 4.2.46
# Description: This is a Script.
. /etc/init.d/functions
start(){
#/etc/init.d/nginx
systemctl start nginx
if [ -f /var/run/nginx.pid ]
then
action "nginx start is" true
else
action "nginx start is" false
fi
}
stop(){
systemctl stop nginx
if [ -f /var/run/nginx.pid ]
then
action "nginx start is" false
else
action "nginx start is" true
fi
}
reload(){
systemctl reload nginx
if [ -f /var/run/nginx.pid ]
then
action "nginx start is" true
else
action "nginx start is" false
fi
}
status(){
if [ -f /var/run/nginx.pid ]
then
echo -e "nginx is \033[32m running... \033[0m"
else
echo -e "nginx is \033[31m death... \033[0m"
fi
}
restart(){
systemctl restart nginx
if [ -f /var/run/nginx.pid ]
then
action "nginx start is" true
else
action "nginx start is" false
fi
}
case $1 in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
status)
status
;;
*)
echo "语法: sh `basename $0` [start|stop|reload|staus|restart]"
esac
先创建一个文件 用来记录
[root@alice scripts]# touch name.tx
[root@alice scripts]# cat zhuajiu.sh
#!/bin/bash
# Author: dang kai
# Blog: www.dkaiyun.com
# Time: 2019-03-21 15:07:43
# Name: zhuajiu.sh
# Version: 4.2.46
# Description: This is a Script.
while true
do
num=`echo $((RANDOM%100))`
chongfu=`grep -w "$num" name.txt |wc -l`
if [ $chongfu -eq 1 ]; then
continue
# elif [ ${#name} -eq 0 ]; then
# continue
# elif [ "$name" = "exit" ]; then
# break
else
read -p "请输入您的英文名[jenny]: " name
[ ${#name} -eq 0 ] && continue
[ "$name" = "exit" ] && break
echo -e "$name \t $num " | tee -a name.txt
fi
done
cat name.txt |sort -nrk2|head -n3
h 显示命令帮助
f 显示登陆信息
d 显示磁盘挂载
m 查看内存使用
u 查看系统负载
q 退出程序
menu(){
cat<
while true
do
ran=`echo $((RANDOM%100+1))`
sum=$(($sum+$ran))
if [ $sum -gt 1000 ]
then
echo "结果为 $sum"
break
fi
done
while true
do
ran=`echo $((RANDOM%100+1))`
sum=$(($sum+$ran))
if [ $sum -gt 1000 ]
then
break
fi
done
zhengshu=`echo $((RANDOM%3))`
if [ $zhengshu -eq 0 ];then
echo "随机数为 $sum 并且可以被3整除 "
else
echo "随机数为 $sum 不可以被3整除 "
fi
file=`find /tmp -type f -size +4k `
ls -l $file |awk '{print $5,$6,$7,$8,$NF} '
array=(1 2 3 4 5 6)
for i in `echo ${array[*]}`
do
echo "$i"
done
array=(I am oldboy teacher welcome to training class)
for i in `echo ${array[*]}`
do
length=`echo $i |wc -L`
if [ $length -gt 6 ];then
echo "$i"
fi
done