2

我想从一个主 shell 脚本运行 2 个不同的脚本。

  • 第一个使用以下命令“rosh -n -l abcd”(它将以用户 abcd 登录到服务器,并且在同一个 shell 上我需要运行另一个script#2script#3...等等。)

    脚本#2- 从那里我需要更改用户su - xyz并提供密码(如果我可以在文件中硬编码它就可以了)(脚本名称是 logintoServer)

    脚本#3- 在同一个 shell 中运行一些脚本来验证服务器的开始停止...

我做了以下但失败了

  • 我有一个脚本rosh -n <servername> -l abcd /bin/sh -c "su - xyz"(我必须在同一个 shell 中运行这个命令)

    以下是错误:

    1. 执行“标准输入必须是 tty”时出现错误
    2. 我试图创建 2 个不同的脚本并运行,但问题是一旦第一个脚本运行,它不会运行第二个脚本,直到我退出脚本。(我需要从第一个脚本创建的子 shell 运行第二个脚本......)
4

1 回答 1

0

I don't have rosh and I don't have a man page for rosh but a similar problem exists with ssh:

ssh localhost /bin/bash -c 'echo x' # (prints nothing)
ssh localhost "/bin/bash -c 'echo x'" # x
ssh localhost "/bin/bash -c 'tty'" # not a tty
ssh -t localhost "/bin/bash -c 'tty'" # /dev/pts/12\nConnection to localhost closed.
ssh localhost "/bin/bash -c 'su - $USER'" # su: must be run from a terminal
ssh -t localhost "/bin/bash -c 'su - $USER'"

the last asked for a password and then gave me a shell, so that would be 2 of 3 steps.

so one idea is to see if rosh has the -t option, too and the other is to enclose /bin/bash... with quotes, too (will require some escaping for the 3rd level).

What does rosh say with equivalent commands?

UPDATE latest state:

rosh -n $host -l abcd -t "/bin/sh -c 'su - $user'"

Next I would save one step by saying /bin/su - xyz instead /bin/sh -c 'su - xyz', then you can use single quotes later, e.g.

rosh -n $host -l abcd -t "/bin/su - $user -c 'echo $PATH'"

this should print $PATH as seen by the echo command. Apparently it doesn't contain java. try man su, which java, man which. su ... -c cmd runs cmd with the shell specified in /etc/passwd, so say </etc/passwd grep $user on the remote machine to find out which shell is used. if it's bash you can change $PATH in .bashrc or so, for other shells I don't know exactly.

Or specify an absolute path when launching java.

regarding password: with ssh I managed to use private key / public key and ssh-agent. For rosh I don't know if that works, too.

于 2013-06-04T05:23:20.870 回答