我有一个名为deployment.sh的子脚本和一个名为deloy_base.sh的父脚本。在父deploy_base.sh上,iam通过其他服务器上的ssh调用子脚本。实际上,子脚本正在执行部署过程。如果子脚本中的任何命令失败,错误状态应该发送到父脚本,以便我可以根据子脚本的成功或失败错误代码发送电子邮件。
现在,不管子脚本中的任何命令失败了,它总是会成功。请帮帮忙。
ssh user@10.0.0.1 "/home/scripts/deployment.sh" DEV 2>&1 | tee /home/release/DEV.log
if [ $?
我通常对PHP的exit()进行编码是有原因的(即exit("You are not authorised to access this page");),但直到最近我才注意到这会发送出退出代码0。
如何使exit在发送原因的同时发送1或更高的退出代码,同时避免使用下面的psuedo代码。
<?php
if ($user->isAdmin() !== true) {
echo "You are not authorised to access this page.";
exit(1);
}
用于重现此问题的代码;尽管它可能并不是
man bash包含了使用trap的文档:
trap [-lp] [[arg] sigspec ...]
…
The ERR trap is not executed if the failed command is part of the command list
immediately following a while or until keyword, part of the test in an if statement,
part of a && or || list, or if the command's return v
我有最基本的脚本:
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork');
} else if ($pid) {
// we are the parent
echo "parent done";
pcntl_wait($status); //Protect against Zombie children
echo "all done";
} else {
// we are the child
echo
我试图在远程服务器上执行本地脚本,方法是将它写入ssh命令的标准输入。脚本运行良好,但是ssh没有退出:它只是挂起,而控件没有返回到父脚本。
母壳牌:
for HOSTNAME in ${HOSTS} ; do
ssh -t -t $HOSTNAME "bash -s" < ~backup_conf.sh
done
称为脚本:
#!/bin/sh
AGENT_BASE_PATH=/home/lokesh
if [ -d "$AGENT_BASE_PATH/CI/DE_deployment/conf" ]; then
i