提问人:Adam Marshall 提问时间:11/14/2023 最后编辑:marc_sAdam Marshall 更新时间:11/23/2023 访问量:18
使用进程时,使用带有 get name 的 sudo 运行脚本会返回 root,但对于其他一些不 c 的脚本则不会#
Run script using sudo with a get name inside returns root when using processes but doesnt for some other script that doesnt c#
问:
所以我有一个脚本,它是一个主控制器,它有
Environment.GetEnvironmentVariable("SUDO_USER")
它返回 sudo 用户用户名,它应该使用这个脚本在 crontab 中使用 sudo 运行,它工作正常,但是我有另一个脚本是使用进程从这个脚本运行的
private static string RunCommand(string cmd)
{
var psi = new ProcessStartInfo();
psi.FileName = "/usr/bin/sudo";
psi.Arguments = cmd;
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
var process = Process.Start(psi);
process.WaitForExit();
var output = process.StandardOutput.ReadToEnd();
return output;
}
但是,当它运行时
Environment.GetEnvironmentVariable("SUDO_USER")
它返回它不应该返回的根,我有另一个脚本可以执行相同的操作,其调用方式相同。
奇怪的是,这昨天还在工作,但是当我今天登录时,它已经这样做了,我已经用同一个用户和所有东西登录了。
我试过把它改成
Environment.GetEnvironmentVariable("USER")
但这只会在所有脚本上返回 root,这是预期的
答: 暂无答案
评论