1、编写脚本,判断当前系统剩余内存大小,如果低于100M,邮件报警管理员,使用计划任务,每10分钟检查一次。第一题第二题第三题∶
1、编写脚本,判断当前系统剩余内存大小,如果低于100M,邮件报警管理员,使用计划任务,每10分钟检查一次。vim men.sh #!/bin/bash men=`free -m | grep Men | tr -s " " " " | cut -d " " -f 4 if [[ $men -lt 100 ]];then echo "内存不足"|mail -s 内存报警 admin@admin.com fi crontab -e */10 * * * * /men.sh tail -f /var/log/cron第一题
1.判断某个文件是否存在,若不存在则给一个Filename does not exist的信息,并终端程序;
⒉若文件存在,则判断它是文件或者目录,结果输出Filename is regular file或者Filename is directory.
3.判断下,执行者的身份对这个文件或者目录所有的的权限,并输入权限数据、
#!/bin/bash read -p "请输入名称:" mingcheng if [[ -e $mingcheng ]];then if [[ -f $mingcheng ]];then echo "Filename is regular file";ls -l $mingcheng else if [[ -d $mingcheng ]];then echo "Filename is directory";ls -l -d $mingcheng fi fi else echo "Filename does not exist";exit 7 fi第二题
1.当执行一个程序的时候,这个程序会让用户选择Y或N
2.如果用户输入Y或者y时就显示ok,continue
3.如果用户输入N或者n时,就显示oh,interrupt
4.如果不是Y/y/N/n之内的其他字符,就显示I don’t know what your chocie is
#!/bin/bash read -p "请输入Y或N:" huang if [[ $huang =~ ^[YyNn]+$ ]];then if [[ $huang =~ ^[Yy]+$ ]];then echo ok,continue else echo oh,interrupt fi else echo "I don't know what your chocie is" fi第三题∶
1.程序的文件名是?
2.共有几个参数
3.若参数的个数小于2则告知使用者数量太少
4.全部参数内容是什么
5.第一个参数是什么
6第三个参数是什么
#!/bin/bash name=$0 echo "文件名是$name" quantity=$# echo "参数个数:$quantity" [[ $quantity -le 2 ]] && echo "参数数量太少了" content=$* echo "参数内容:$content" first=$1 echo "第一个参数是:$first" third=$3 echo "第三个参数是$third"



