shell script debug

本文介绍如何使用bash命令进行Shell脚本的语法检查、命令回显、详细运行过程查看,以及在crontab中调试的方法。同时,提供解决环境变量和路径问题的策略。

shell脚本调试


方法一:

bash    -n   scriptfile     只检查语法错误,不执行命令

bash   -u     scriptfile      如果使用了未定义的变量就给出出错消息

bash   –un   scriptfile        查看是否有未定义变量


bash   -v   scriptfile     在执行命令之前回显他们

bash   -x   scriptfile     打印执行的每一行命令和当前状态

bash   -vx   sciptfile      查看脚本详细运行过程


方法二:

还可以用echo模拟断点来打印输出信息。

方法三:

输出到日志

>   X.log  2>&1 


---------------------------------------------------

在crontab中的调试:


如果在命令行跑过了,在crontab跑不过可以在脚本第一行加上配置文件:

source ~/.bash_profile (不同的系统配置文件可能不同)


有时候是解释器不同,所以这样也能跑过:

bash   $dir/$yourscript.sh


无非是环境变量和路径的问题。


未完待续......


RROR: MyFSDataInputStream is not COMMAND nor fully qualified CLASSNAME. Usage: hadoop [OPTIONS] SUBCOMMAND [SUBCOMMAND OPTIONS] or hadoop [OPTIONS] CLASSNAME [CLASSNAME OPTIONS] where CLASSNAME is a user-provided Java class OPTIONS is none or any of: buildpaths attempt to add class files from build tree --config dir Hadoop config directory --debug turn on shell script debug mode --help usage information hostnames list[,of,host,names] hosts to use in worker mode hosts filename list of hosts to use in worker mode loglevel level set the log4j level for this command workers turn on worker mode SUBCOMMAND is one of: Admin Commands: daemonlog get/set the log level for each daemon Client Commands: archive create a Hadoop archive checknative check native Hadoop and compression libraries availability classpath prints the class path needed to get the Hadoop jar and the required libraries conftest validate configuration XML files credential interact with credential providers distch distributed metadata changer distcp copy file or directories recursively dtutil operations related to delegation tokens envvars display computed Hadoop environment variables fedbalance balance data between sub-clusters fs run a generic filesystem user client gridmix submit a mix of synthetic job, modeling a profiled from production load jar <jar> run a jar file. NOTE: please use "yarn jar" to launch YARN applications, not this command. jnipath prints the java.library.path kdiag Diagnose Kerberos Problems kerbname show auth_to_local principal conversion key manage keys via the KeyProvider rbfbalance move directories and files across router-based federation namespaces rumenfolder scale a rumen input trace rumentrace convert logs into a rumen trace s3guard S3 Commands version print the version Daemon Commands: kms run KMS, the Key Management Server registrydns run the registry DNS server SUBCOMMAND may print help when invoked w/o parameters or with -h.
10-23
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值