我有一些脚本要server-2
通过ssh from在远程server()上执行server-1
,我必须将该输出写入名为file.log
on的日志文件中server-1
。
我正在尝试: sc.sh
echo 'testing'
cp $HOME/dir1/file1 $HOME/dir2
现在,执行sc.sh
通过ssh:
sshpass -p 'psswd' ssh username@server-2 "bash -s" < sc.sh | tee -a file.log
if [ $? -eq 0]; then
echo "successfully executed the script file"
.
.
.
else
echo "failed copying due to incorrect path"
fi
现在由于tee -a file.log
命令的缘故,即使我在脚本文件中的命令失败,它也将始终返回0。我该如何写入日志文件,并应ssh
根据ssh
命令退出代码检查命令后的if条件,该条件应该起作用?
检查${PIPESTATUS[0]}
对我有用...
if [ ${PIPESTATUS[0]} -eq 0 ]; then
echo "successfull"
fi
echo ${PIPESTATUS[*]}
打印所有管道命令的退出代码。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句