shell脚本实现监控shell脚本的执行流程及变量的值
很多时候,我们都会写shell程序来完成一些不用重复造轮子的时刻,但是,又因为shell语句中也会有函数,也会有变量,在运行后到底执行了哪些相关的操作,就需要对具体执行过程中的变量等可变的因素的监控,那么我们下面就写个小小的shell例子,来完成这个对执行过程中条件语句中的变量的变化的监控和整个程序的执行流程的观察。
shell程序代码:
#!/bin/bash functionsetlogfile { if![-z"$1"];then echo"logfilenameisnotempty!">>kthh exec2>>$1 exec1>>$1 fi }
num1=$1 logfile=$2 execlogfile=$3
setlogfile${execlogfile} set-x if[$num1-eq0];then echo"num1is0">>${logfile} elif[$num1-ge0];then echo"num1isgrate0">>${logfile} else echo"num1isless0">>${logfile} fi /sbin/shutdown-k10 if[$num1-eq0];then echo"num1is0again">>${logfile} fi