2023年11月27日发(作者:)

shell脚本命令状态码

问题

脚本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/

exit 1

fi

awk 'NR==3{print $3}' $file >> /home/oracle/ETL/

解决步骤

查看 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

显⽰结果:

总结

使⽤管道命令后⾯连接起来写在⼀⾏的命令,不是⼀条命令,是分步执⾏的。