我需要能够在脚本中运行脚本,但首先我需要ssh作为不同的用户,然后更改我的组。
我目前在perl脚本中执行以下操作:
`ssh <user>@<host> ; newgrp <group> ; /script/to/run.pl`
从命令行运行此命令时,它不会切换到切换组。我认为这是因为它正在改变为一个新的shell。
如何解决这个问题并使其发挥作用?
另外,请注意,我没有sudo / root privelages。
答案 0 :(得分:2)
第一个分号由本地shell解释。因此这三个命令在同一主机上运行。我想你想要这个
ssh <user>\@<host> "newgrp <grp>; /bin/run.pl"
答案 1 :(得分:1)
sg $group -c '$cmd'
以下命令的原因:
newgrp <int>
不起作用是因为它创建了一个新的shell。至少这是我最好的猜测。 &#34; sg&#34;命令绕过这个。
答案 2 :(得分:1)
我发现以下方法可以工作(在ksh
上使用hpux
):
ssh user@host "echo 'date;pwd;echo bozo;id' | newgrp nerds;"
基本上以user:nerds
的身份执行命令:
答案 3 :(得分:0)
我认为OP想要构造一个从Perl执行的字符串,注意反引号。不确定,但OP可能不得不使用:
$s='ssh <user>@<host> ; newgrp <group> ; /script/to/run.pl'; # Normal single quotes not backticks
exec($s);
OP,有不同的方法从Perl脚本执行shell函数。你使用了反引号。还有exec($ s)和系统($ s)。