Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.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
如何以不同的用户身份ssh、更改组和在Perl中运行脚本_Perl - Fatal编程技术网

如何以不同的用户身份ssh、更改组和在Perl中运行脚本

如何以不同的用户身份ssh、更改组和在Perl中运行脚本,perl,Perl,我需要能够从脚本中运行脚本,但首先我需要以不同的用户身份使用ssh,然后更改我的组 我目前正在perl脚本中执行以下操作: `ssh <user>@<host> ; newgrp <group> ; /script/to/run.pl` `ssh@;新玻璃钢/script/to/run.pl` 当从命令行运行此命令时,它不会连接到开关组。我想这是因为它正在换一个新的外壳 我该如何解决这个问题并让它发挥作用 另外,请注意,我没有sudo/root特权。第一个

我需要能够从脚本中运行脚本,但首先我需要以不同的用户身份使用ssh,然后更改我的组

我目前正在perl脚本中执行以下操作:

`ssh <user>@<host> ; newgrp <group> ; /script/to/run.pl`
`ssh@;新玻璃钢/script/to/run.pl`
当从命令行运行此命令时,它不会连接到开关组。我想这是因为它正在换一个新的外壳

我该如何解决这个问题并让它发挥作用


另外,请注意,我没有sudo/root特权。

第一个分号由本地shell解释。因此,这三个命令在同一台主机上运行。我想你想要这个

ssh <user>\@<host> "newgrp <grp>; /bin/run.pl"
ssh\@“newgrp;/bin/run.pl”

第一个分号由本地shell解释。因此,这三个命令在同一台主机上运行。我想你想要这个

ssh <user>\@<host> "newgrp <grp>; /bin/run.pl"
ssh\@“newgrp;/bin/run.pl”

我认为OP想要构造一个字符串,以便从Perl执行,请注意backticks。不确定,但OP可能必须使用:

$s='ssh <user>@<host> ; newgrp <group> ; /script/to/run.pl'; # Normal single quotes not backticks
exec($s);
$s='ssh@;新玻璃钢/script/to/run.pl'.#正常单引号而非反勾号
行政总裁(港币);;

当然,有不同的方法可以从Perl脚本执行shell函数。你用了反勾。还有exec($s)和system($s)

我认为OP想要构造一个字符串来从Perl执行,请注意backticks。不确定,但OP可能必须使用:

$s='ssh <user>@<host> ; newgrp <group> ; /script/to/run.pl'; # Normal single quotes not backticks
exec($s);
$s='ssh@;新玻璃钢/script/to/run.pl'.#正常单引号而非反勾号
行政总裁(港币);;

当然,有不同的方法可以从Perl脚本执行shell函数。你用了反勾。还有exec($s)和system($s)

萨尔瓦在他的回答中回答了我的问题:

sg $group -c '$cmd'
执行以下命令的原因:

newgrp <int>
newgrp

不起作用是因为它创建了一个新的外壳。至少这是我最好的猜测。“sg”命令绕过了这个问题。

萨尔瓦在他的回答中回答了我的问题:

sg $group -c '$cmd'
执行以下命令的原因:

newgrp <int>
newgrp

不起作用是因为它创建了一个新的外壳。至少这是我最好的猜测。“sg”命令解决了这个问题。

我发现以下方法可以使用(在
hpux
上使用
ksh
):


它基本上是以
user:nerds
的身份执行命令的:

我发现以下方法是有效的(使用
hpux上的
ksh
):


它基本上以
user:nerds

sg$group-c'$cmd'
的形式执行命令,这非常有效<代码>sg$group-c'$cmd'
这非常有效!是的,更改当前用户或组的实用程序(
su
sg
nwegrp
sudo
等)始终会启动新shell。这是因为程序无法更改其父进程的凭据。它只能更改自己的,然后由其后代继承。是的,更改当前用户或组的实用程序(
su
sg
nwegrp
sudo
等)始终启动新的shell。这是因为程序无法更改其父进程的凭据。它只能改变自己,然后让后代继承。