Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash Shell脚本在切换用户后自动退出SSH部分(通过pbrun命令)_Bash_Shell_Ssh_Su - Fatal编程技术网

Bash Shell脚本在切换用户后自动退出SSH部分(通过pbrun命令)

Bash Shell脚本在切换用户后自动退出SSH部分(通过pbrun命令),bash,shell,ssh,su,Bash,Shell,Ssh,Su,我有下面的代码 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 在上述情况下,它不会在切换用户后显示命令

我有下面的代码

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
在上述情况下,它不会在切换用户后显示命令的后续输出

问题未发生时的输出

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

这有什么原因/解决方法吗?即使是一个解决办法也应该适合我。。!谢谢

传递一个内部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

ssh一些_user@server嗨,查尔斯,谢谢你的回复。!我也累了,但还是不走运。它在执行pbrun命令后自动退出。奇怪的是,有时它会自动工作..根据您的建议修改代码..==#/bin/bash-sshviranka@rmhodtest03.oracle.com您会注意到,我编写了
…另外,告诉
pbrun
调用
bash
是非常重要和有意的——如果它将内部herdoc的内容传递给shell以外的任何对象的stdin,则行为是未定义的,只需在换行后立即使用
internal_EOF
来终止内部herdoc,而不是
'internal_EOF'
;引号是shell的标志,而不是标志本身的一部分。@user2928822,…简而言之,在尝试进行修改之前,请严格按照我给出的代码进行测试(除了调整用户名)。
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