远程登录服务器的脚本

远程登录服务器的脚本

我正在使用 Ubuntu bash。我想通过 shell 远程登录服务器,它会给我自己的命令行。然后输入“shell”,再次输入登录凭据,然后输入命令。我需要在屏幕上打印该命令输出。请建议,我该怎么做?

答案1

ssh HOSTNAME "run_command with arguments"

将执行命令运行命令并传递两个参数 - 1:“with”和 2:“arguments”;-) OUTPUT 将像往常一样转到 stdout .. 因此,如果您想检查目录中的文件邪恶的东西,例如:

#!/bin/bash
host=my-server.biz
check="/opt/path/to/check"
list=`ssh $host "ls $check"`
evil=`echo -e "$list"|grep -c "evil"`
if [ $evil -eq 0 ]; then
  echo "all is well"
else
  echo "the end is nigh"
fi

相关内容