我打算写一个小程序。这个程序的输入应该是 Linux 机器的 IP、用户名和密码,它应该给我该机器的系统详细信息作为输出。
我打算使用 Shell 编写此代码,使用 RSH 进行登录。我绝不要求解决方案,但您能否指出我拥有的其他选择?我不太习惯使用 Shell 脚本。
提前致谢
最佳答案
我也有同样的需求。我所做的是:
首先编写一个将在目标主机(T)上执行的脚本。像这样
> cat check_server.sh
#!/usr/bin/env bash
# execute at target host
all_cmd=(
"uname -a"
"lscpu"
"free -m"
)
function _check {
for one_cmd in "${all_cmd[@]}"; do
echo -e "\n\n$one_cmd" >> /tmp/server_info.txt
eval "$one_cmd" >> /tmp/server_info.txt
done
}
然后在target中执行并复制结果,像这样
_cmd=`base64 -w0 check_server`
ssh $user@$ip "echo $_cmd | base64 -d | bash"
scp $user@$ip:/tmp/server_info.txt ./
关于linux - 从 Red Hat Linux 收集系统数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42105815/