[英]Shell Script automatically exits from SSH section after switching of user (through pbrun command)
I have the below piece of code.. 我有下面的代码..
ssh some_user@server << EOF
echo 'Successfully connected to the server'
pbrun previlige -u user
ls
pwd
id
...few more commands
EOF
if [ $? -eq 0 ]
then
echo 'Successful Execution of the last command in ssh'
fi
Now the issue that I face in the above code is, the script automatically exits after switching user through the pbrun command (ie it never executes the ls , pwd and subsequent commands). 现在,我在上面的代码中遇到的问题是,该脚本在通过pbrun命令切换用户后自动退出(即,它从不执行ls , pwd和后续命令)。 To make things complicated, this issue is intermittent.
使事情变得复杂的是,这个问题是断断续续的。 Sometimes I get the proper output of all the subsequent commands and sometimes I don't.
有时我得到所有后续命令的正确输出,有时却没有。
Output when the issue occurs: 发生问题时的输出:
Successfully connected to the server
su from some_user to user at Mon Oct 6 09:47:00 MDT 2014
Successful Execution of the last command in ssh
In the above case it never displays the subsequent output of commands after switching the user 在上述情况下,切换用户后从不显示命令的后续输出
Output when the issue doesn't occur 当没有出现问题时输出
Successfully connected to the server
su from some_user to user at Mon Oct 6 09:47:00 MDT 2014
Logs migrate.properties prereq.sh src_exp.sh src_mig.exp
/home/venus/
uid=* gid=* groups=****
Successful Execution of the last command in ssh
Is there any cause/fix for this? 是否有任何原因/解决办法? Even a workaround should be fine for me..!
即使是解决方法,对我来说也没问题。 Thanks!
谢谢!
Passing an inner heredoc ensures that your later contents are fed to pbrun
's stdin, rather than invoked in the outer shell only after pbrun
exits, which is what would happen otherwise: 传递内部的Heredoc可确保将以后的内容馈送到
pbrun
的stdin,而不是仅在pbrun
退出后才在外壳程序中调用,否则会发生这种情况:
ssh some_user@server <<'OUTER_EOF'
echo 'Successfully connected to the server'
pbrun -u user bash <<'INNER_EOF'
# this is inside both ssh and pbrun
ls
pwd
id
INNER_EOF
# this is inside ssh, but not inside pbrun
OUTER_EOF
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.