
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
원격 쉘은 여기서 string()을 이해하지 못하는 것 같습니다 <<<string
. Here-strings는 POSIX 표준의 확장이며 모든 쉘에서 이해되지 않을 수 있습니다.
대신 로컬로 리디렉션하고 at
원격으로 호출하세요.
sshpass -p 'passw' \
ssh -o StrictHostKeyChecking=no \
[email protected] \
'at 11:04 Dec 10' <<<'touch /tmp/test_file'
이는 로컬 대화형 쉘이 이 문자열을 지원한다고 가정합니다.
이 문자열을 완전히 사용하지 않을 수도 있습니다.
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"**
이는 파일 생성 예와 같은 쉘 스크립트와 함께 작동합니다.
at 13:14 Dec 13 <<EOF
touch /tmp/atran3
EOF