问题
脚本ls 执行没有找到目标文件,在脚本中已经判断了状态码,执行失败应该退出脚本。
错误:ls: cannot access /home/oracle/ETL/tmp_crl_cl/*mid_order_item_mon*: No such file or directory
shell 脚本:
file=`ls /home/oracle/ETL/tmp_crl_cl/*$1*| head -n1`
if [ $? != 1 ];then
echo 未知错误 >> /home/oracle/ETL/1.txt
exit 1
fi
awk 'NR==3{print $3}' $file >> /home/oracle/ETL/1.txt
解决步骤
1.pstree查看 shell脚本进程
参数
-p Show PIDs. PIDs are shown as decimal numbers in parentheses after each process name. -p implicitly disables compaction.
-a Show command line arguments. If the command line of a process is swapped out, that process is shown in parentheses. -a implicitly disables
compaction.
命令:
pstree -pa 46208
显示结果:
sh,46208 tmp_20190401.sh mid_order_item_mon
└─awk