下午好。上有一个/etc/profile.d/
脚本bash
,按计划在通过 SSH 连接时显示各种信息。
但是,重新启动机器后,通过图形 shell 登录变得根本不可能(Gnome 环境):我选择用户,输入密码,然后返回用户选择的窗口。同时,通过 SSH 连接时,脚本在终端中运行也没有问题。
从那里删除脚本后,通过图形 shell 登录就可以了。
如何解决这个问题?
UPD。脚本
#!/bin/bash
# Font furniture
b=$(tput bold);
n=$(tput sgr0);
# Functions
func_PrintResourceUsage() {
if [ -z "$3" ]; then
echo -e "\t${n}$1\t\t${b}$2${n}";
else
echo -e "\t${n}$1\t\t${b}$2${n}\tof \t${b}$3";
fi;
}
echo -e;
# CPU info
loadavg=$(cat /proc/loadavg);
echo -e "${LinesPrefix}${b}CPU usage:";
func_PrintResourceUsage " 1 min" $(echo $loadavg | awk '{ print $1 }') "";
func_PrintResourceUsage " 5 min" $(echo $loadavg | awk '{ print $2 }') "";
func_PrintResourceUsage "10 min" $(echo $loadavg | awk '{ print $3 }') "";
echo -e;
# RAM info
RAMTotal=$(free -h | awk 'FNR == 2 { print $2 }');
RAMUsed=$(free -h | awk 'FNR == 2 { print $3 }');
SWAPTotal=$(free -h | awk 'FNR == 3 { print $2 }');
SWAPUsed=$(free -h | awk 'FNR == 3 { print $3 }');
echo -e "${LinesPrefix}${b}Memory usage:"
func_PrintResourceUsage "RAM" ${RAMUsed} ${RAMTotal};
func_PrintResourceUsage "SWAP" ${SWAPUsed} ${SWAPTotal};
echo -e;
# Disc space info
MountArr[0]="/";
echo -e "${LinesPrefix}${b}Disc usage:";
for Mount in "${MountArr[@]}"; do
MountPointInfo=$(/bin/df -Th $Mount 2>/dev/null | tail -n 1);
MountPointFreeSpace=( \
$(echo $MountPointInfo | awk '{ print $4 }') \
$(echo $MountPointInfo | awk '{ print $3 }') \
);
func_PrintResourceUsage $Mount ${MountPointFreeSpace[0]} ${MountPointFreeSpace[1]};
done
echo -e;
#users
UsersOnlineCount=$(users | wc -w);
echo -ne "${LinesPrefix}${b}Users logged in:"
echo -e " ${b}${UsersOnlineCount}";
echo -e;
# uptime
SystemUptime=$(uptime | sed 's/.*up \([^,]*\), .*/\1/');
echo -ne "${LinesPrefix}${b}System uptime:"
echo -e "\t${b}${SystemUptime}";
echo -e;
profile.d 中的脚本一个一个运行,PATH 变量可能尚未设置,脚本将在其中一个命令上发出 exit 1,这会进一步中断脚本的执行。如果不加载其环境变量(相同的 PATH),图形 shell 可能无法启动。
我建议将此脚本放在 bash.rc 中,以便仅在您输入 bash 时执行