Sri*_*nth 10 scripting ssh solaris
如何通过 ssh 以批处理模式运行命令?也就是说,ssh
命令的等价物是sftp -b <filename> <hostname>
什么?
我有一组命令,我希望在一组通过ssh
. 结束后sftp
,我将命令存储在一个文件中filename
并连接到主机并使用前面提到的命令运行这些命令。
这样的事情可能结束ssh
吗?
如果我错了,请纠正我,但您似乎想在脚本位于本地的远程服务器上运行常规 shell 命令。
#!/bin/sh
trap "rm -f /tmp/sendonssh.$$.*" 0 1 2 3 15
# commands to run on the remote server
cat <<'EOF' >> /tmp/sendonssh.$$.sh
mkdir -p /tmp/foobar.$$
mv $HOME/xyzzy /tmp/foobar.$$
chmod 640 $HOME/xyzzy
EOF
# call for each argument
for userhost in "$@"; do
errorout=`ssh -aTxo BatchMode=yes $userhost /bin/sh -s < /tmp/sendonssh.$$.sh 2>&1`
rc=$?
if [ $rc -ne 0 ]; then
echo "Error: $userhost: $errorout"
exit $rc
fi
done
Run Code Online (Sandbox Code Playgroud)
我做这个用的不是shell的Python在我的测试环境中的某些“远程执行”应用:ssh $userhost python < $pythonscriptfilename
。
SSH 等价物sftp -b <filename> <hostname>
将是:
ssh -o BatchMode=yes <hostname> sh -s < "<filename>"