chinalinux

#!/bin/bash
cat <<EOF
*-(A)输入A查看/etc/password最后5个用户。
*-(B)输入B的话就显示系统开机时间多久了
*-(C)输入C的话就判断当前磁盘根目录使用情况是否超过50%,如果超过50%就显示“disk space is used over 50%”;如果没超过50%就显示“disk space is user below 50%”
*-(D)输入D的话就显示出系统当前处于LISTEN状态的PID进程程序名称,以“program-name(pid)”这种形式显示。
*-(E)输入E的话获取系统的IP和掩码,以"IP/NETMASK"形式显示
*-(F)输入F的话添加系统用户,完了后添加该用户密码(记得给以提示操作)
*-(G)输入G的话显示系统使用率最多的10条命令,还有使用的次数
EOF
read -p "请输入你的选择 A|B|C|D|E|F|G: " input
case $input in
A)
tail -n 5 /etc/passwd | awk -F: \'{print "user:"$1, "UID"$3}\'
;;
B)
awk \'{print $1/60/60"hours"}\' /proc/uptime
;;
C)
df -h | awk \'$6=="/"{if($5>50)print "disk space is used over 50%";else print "disk space is user below 50%"}\'
;;
D)
netstat -nptl | awk \'/LISTEN/{print $7}\'|awk -F/ \'{print $2"("$1")"}\'
;;
E)
ifconfig eth0 | awk -F"[ :]+" \'NR==2{print $4"/"$NF}\'
;;
F)
echo -e "Please input username"
read user
echo -e "Please input password"
read pass
useradd $user
echo $pass | passwd --stdin $user
;;
G)
awk \'{++a[$1]}END{for(i in a)print i,a[i]|"sort -k2 -nr"} ~/.bash_history\' | head
;;
*)
printf "your input is wrong\n"
;;
esac

分类:

技术点:

相关文章:

  • 2019-09-02
  • 2021-12-22
  • 2021-09-11
  • 2021-11-07
  • 2022-01-10
  • 2021-12-18
猜你喜欢
  • 2021-11-12
  • 2021-11-12
  • 2019-12-26
  • 2021-05-16
  • 2021-04-09
  • 2021-07-02
  • 2018-05-11
相关资源
相似解决方案