设为首页 加入收藏

TOP

企业Shell面试题及企业运维实战案例(三)(三)
2019-09-03 02:40:12 】 浏览:469
Tags:企业 Shell 试题 实战 案例
nctions cat
<<EOF =================================== 1.[install lamp] 2.[install lnmp] 3.[install nfs] 4.[exit] =================================== EOF while true do read -p "pls input the num you want:" num case $num in 1) /bin/sh /server/scripts/lamp.sh action "startinstalling lamp..." /bin/true ;; 2) /bin/sh /server/scripts/lnmp.sh action "startinstalling lnmp..." /bin/true ;; 3) /bin/sh /server/scripts/nfs.sh action "startinstalling nfs..." /bin/true ;; 4) exit ;; *) echo "对不起,输入错误,请重新输入" esac done

12、企业Shell面试题12:Web及MySQL服务异常监测案例

①通过端口:
#!/bin/sh
. /etc/init.d/functions
port=`lsof -i:80|grep nginx|wc -l`
if [ $port -ge 2 ];then
  action "Nginx is running" /bin/true
else 
  action "Nginx is not running" /bin/false
  /application/nginx/sbin/nginx
  action "starting Nginx" /bin/true
fi 
②通过进程:
#!/bin/sh
. /etc/init.d/functions
port=`ps -ef|grep nginx|grep -v grep|wc -l`
if [ $port -ge 2 ];then
  action "Nginx is running" /bin/true
else 
  action "Nginx is not running" /bin/false
  /application/nginx/sbin/nginx
  action "starting Nginx" /bin/true
fi
③wget返回内容:
#!/bin/sh
. /etc/init.d/functions
port=`wget -T 5 --spider http://172.19.5.8 &>/dev/null`
if [ $? -eq 0 ];then
  action "Nginx is running" /bin/true
else 
  /application/nginx/sbin/nginx
  action "starting Nginx" /bin/true
fi
④curl返回值200:
#!/bin/sh
. /etc/init.d/functions
port=`curl -s -I -w "%{http_code}\n" 172.19.5.8 -o /dev/null`
if [ "$port" == "200" ];then
  action "Nginx is running" /bin/true
else 
  /application/nginx/sbin/nginx
  action "starting Nginx" /bin/true
fi

13、企业Shell面试题13:监控Memcached缓存服务是否正常

监控Memcached缓存服务是否正常,模拟用户(web客户端)检测。
使用nc命令加上set/get来模拟检测。 

 

14、企业Shell面试题14:开发脚本入侵检测与报警案例

面试及实战考试题:监控web站点目录(/var/html/www)下所有文件是否被恶意篡改(文件内容被改了),如果有就打印改动的文件名(发邮件),定时任务每3分钟执行一次。

 

15、企业Shell面试题15:开发Rsync服务启动脚本案例

#!/bin/bash
. /etc/init.d/functions
port=`netstat -lntup|grep 873|wc -l`
if [ ! -f /etc/rsyncd.conf ]
  then
    action "rsync配置" /bin/false
  exit 1
elif [ ! -f /usr/bin/rsync ]
    then
       action "rsync命令" /bin/false
   exit
fi

case "$1" in
  start)
     if [ $port -lt 2 ];then
       rsync --daemon
       action "Starting rsync..." /bin/true
     else
       action "Rsync is running..." /bin/true
     fi
     ;;
  stop)
     if [ $port -ge 2 ];then
     killproc rsync
     action "Stopping rsync..." /bin/true
     else
     action "Rsync is not running..." /bin/true
     fi
     ;;
  restart)
     killproc rsync
     rsync --daemon
     action "Rsync is restarting." /bin/true
     ;;
  *)
     echo "USAGE:$0 {start|stop|restart}"
esac

 16、企业Shell面试题16:开发MySQL多实例启动脚本

开发MySQL多实例启动脚本:
已知MySQL多实例启动命令为:mysqld_safe --defaults-file=/data/3306/my.cnf&
停止命令为:mysqladmin -u root -poldboy123 -S/data/3306/mysql.sock shutdown
请完成mysql多实例启动启动脚本的编写
要求:用函数,case语句、if语句等实现。

解答:

#!/bin/bash
. /etc/init.d/functions
Port="3306"
Myuser="root"
Mypass="123456"
首页 上一页 1 2 3 4 5 下一页 尾页 3/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Installation failed: Timeout wa.. 下一篇Activity生命周期方法调用finish..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目