在登录期间以root身份执行的登录脚本无法获取当前登录用户

问题描述 投票:0回答:0

我正在努力解决如何让以 root 用户身份执行的登录脚本中登录 macbook 的用户。场景是我学校有一堆 macbook,它们有一个登录脚本,每次用户登录计算机时都会运行该脚本。我依靠这个脚本来确定他们应该使用什么 DNS 服务器等。

这个脚本过去只是通过获取 3 美元来获取用户,但现在不再有效,并且运行各种命令来确定谁登录每次都只显示 root,即使我以各种学生身份登录也是如此。剧本:

#!/bin/bash

# Setting DNS by User

# Get variables. $3 is logging in user.
user=$3

thisuser1=`logname`
thisuser2=`id -u -n`
thisuser3=`id -u`

echo -e "Current User: $user\n"
echo -e "logname  = $thisuser1"
echo -e "id -u -n = $thisuser2"
echo -e "id -u.   = $thisuser3"

产量:

Current User:

logname = root
id -u -n = root
id -u. = 0

我很茫然。在此运行期间,我以名为“eric”的用户身份登录。我做错了什么?

bash
© www.soinside.com 2019 - 2024. All rights reserved.