本文目录
- shell 关于 stty的一段代码,新手看不懂
- 写一个unix shell脚本无限循环 3秒一次显示登陆登出到unix系统的用户
- shell 脚本中执行重启完成后继续执行其它的命令
- 如何让shell语句中的 while循环语句不等待一个php执行完就进行下一个循环
- Linux shell脚本里经常出现 while [ 1 ] 什么意思
shell 关于 stty的一段代码,新手看不懂
stty -icanon关闭驱动程序中的规范模式处理,跳过缓冲层,用户不能删除字符
read -t 5 a; echo $a 将屏幕输入放在变量a中,然后输出,赋值给 _key_press
大致注释了一下:
sFirst=1 #标记while true; do #无限循环 _tty_setting=$(stty -g) #将 stty设置保存在_tty_setting stty -icanon #关闭驱动程序中的规范模式处理,跳过缓冲层,用户不能删除字符 if ; then #在这个标记下需要读取输入 _key_press=`read -t 5 a; echo $a` #将屏幕输入放在变量a中,然后输出,赋值给 _key_press else _key_press=1 #另一个分支 isFirst=0 fi if ;then #有输入东西 key_save=$_key_press #放在key_save中 else _key_press=$key_save #没有输入,放上次的东西 fi stty $_tty_setting #恢复stty设置 case $_key_press in #根据不同的东西,处理不同逻辑 1) clear;showDetail ;; 2) clear;showDifferent ;; 3) clear;showMissing ;; 4) clear;showWaiting ;; 5) clear;showSame ;; 6) echo "" echo "bye." exit 0 ;; esacdone
写一个unix shell脚本无限循环 3秒一次显示登陆登出到unix系统的用户
a=`date`b=`who|awk ’{printf $1 "\n"}`echo "$b\n" 》 b.txtwhile doecho "The current time is :$a"echo "The current users are :$b"sleep 30c=`who|awk ’{printf $1 "\n"}`echo "$c\n" 》 c.txtecho `awk ’{print $0}’ b.txt c.txt|sort|uniq -u` 》 tmpfiled=`cat tmpfile|grep -v ^$|wc -l`if thenecho "no user login and logout"elsei=1while doe=`cat tmpfile|awk ’{printf $0 " "}’|awk ’{printf $k}’ k="$i"`if thenecho "user login:$e"elseecho "user logout:$e"filet i=i+1donefiecho "$c\n" 》 b.txtdone
shell 脚本中执行重启完成后继续执行其它的命令
要用循环查询直到重启完成. #!/bin/bash***隐藏网址***if ; then echo "HTTP Server is down. At time: `date`" 》》 /var/log/htmon.log***隐藏网址*** while true do***隐藏网址*** && break sleep 1 done***隐藏网址*** shutdown -r nowfi追问***隐藏网址******隐藏网址***回答之前没理解你要做什么。要防止无限循环,可以对尝试次数做个限制(加个计数器),比如10次尝试后还不成功就尝试修改启动级别并重启操作系统。 count=0flag=0 #标志是否成功, 0-失败,1-成功while #只尝试10次do let count+=1***隐藏网址*** if ; then flag=1 break fi sleep 1done***隐藏网址******隐藏网址*** shutdown -r nowfi
如何让shell语句中的 while循环语句不等待一个php执行完就进行下一个循环
用SHELL子进程,.... (/usr/local/bin/php a.php).....
Linux shell脚本里经常出现 while [ 1 ] 什么意思
1、1带表true2、循环继续while {do sth}3、结论就是无限循环。