![sshpass Solaris One liner 传递命令](https://linux22.com/image/184772/sshpass%20Solaris%20One%20liner%20%E4%BC%A0%E9%80%92%E5%91%BD%E4%BB%A4.png)
我正在尝试将一个 liner sshpass 命令传递到 Solaris 盒子,但不起作用。这些是我尝试过的选项:
sshpass -p "passw" ssh "[email protected]" -o StrictHostKeyChecking=no `at 11:04 Dec 10 <<< touch /tmp/test_file`
sshpass -p "passw" ssh "[email protected]" -o StrictHostKeyChecking=no 'at 11:04 Dec 10 <<< "touch /tmp/test_file"'
sshpass -p "passw" ssh "[email protected]" -o StrictHostKeyChecking=no "at 11:04 Dec 10 <<< "touch /tmp/test_file""
sshpass -p "passw" ssh "[email protected]" -o StrictHostKeyChecking=no "at 11:04 Dec 10 <<< \"touch /tmp/test_file\""
还尝试了这种变化:
"at 11:04 Dec 10 <<<\"touch /tmp/test_file\""
"at 11:04 Dec 10 <<<touch /tmp/test_file"
"at 11:04 Dec 10 <<< touch /tmp/test_file"
'at 11:04 Dec 10 <<<touch /tmp/test_file'
'at 11:04 Dec 10 <<<"touch /tmp/test_file"'
"/sbin/sh at 11:04 Dec 10<<<"touch /tmp/test_file""
我不断收到: 135.102.22.0 sh: 第 1 行语法错误:`<' 意外
也尝试过这个:"at 13:19 Dec 10 <<EOF touch /tmp/atran3 EOF"
这给了我错误:at:错误的时间规范
答案1
远程 shell 似乎不理解此处的字符串 ( <<<string
)。 Here-strings 是 POSIX 标准的扩展,并非所有 shell 都能理解。
相反,在本地进行重定向并at
远程调用:
sshpass -p 'passw' \
ssh -o StrictHostKeyChecking=no \
[email protected] \
'at 11:04 Dec 10' <<<'touch /tmp/test_file'
这假设您的本地交互式 shell 支持此处字符串。
您也可以完全避免使用此处字符串:
echo 'touch /tmp/test_file' |
sshpass -p 'passw' \
ssh -o StrictHostKeyChecking=no \
[email protected] \
'at 11:04 Dec 10'
或者,要安排更长的脚本,请使用此处文档:
sshpass -p 'passw' \
ssh -o StrictHostKeyChecking=no \
[email protected] \
'at 11:04 Dec 10' <<'END_AT_SCRIPT'
touch /tmp/test_file
# Possibly more
# commands here
END_AT_SCRIPT
或者只是将脚本存储在文件中然后发送:
sshpass -p 'passw' \
ssh -o StrictHostKeyChecking=no \
[email protected] \
'at 11:04 Dec 10' <myscript.sh
答案2
如果要安排工作,这对我很有用。安排关闭的示例:
sshpass -p "passw" ssh "[email protected]" -o StrictHostKeyChecking=no **"echo shutdown -h now | at 13:35 Dec 13"**
这适用于 shell 脚本,创建文件的示例:
at 13:14 Dec 13 <<EOF
touch /tmp/atran3
EOF