1

I am trying to pass one liner sshpass command to Solaris box but won't work. those are the options I tried:

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\""

also tried this variations:

"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""

I keep on getting: 135.102.22.0 sh: syntax error at line 1: `<' unexpected

also tried this: "at 13:19 Dec 10 <<EOF touch /tmp/atran3 EOF" and that gives me error: at: bad time specification

1
  • I just checked and yes, there is a shell so I used "/sbin/sh at 11:04 Dec 10 <<< "touch /tmp/test_file"", same error
    – dwt.bar
    Commented Dec 10, 2020 at 17:45

2 Answers 2

4

The remote shell does not seem to understand here-strings (<<<string). Here-strings are an extension to the POSIX standard and not understood by all shells.

Instead, do the redirection locally and just call at remotely:

sshpass -p 'passw' \
ssh -o StrictHostKeyChecking=no \
    [email protected]  \
    'at 11:04 Dec 10' <<<'touch /tmp/test_file'

This assumes that your local interactive shell supports here-strings.

You could also just avoid using here-strings completely:

echo 'touch /tmp/test_file' |
sshpass -p 'passw' \
ssh -o StrictHostKeyChecking=no \
    [email protected]  \
    'at 11:04 Dec 10'

or, for scheduling a longer script, use a here-document:

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

or just store the script in a file an send it over:

sshpass -p 'passw' \
ssh -o StrictHostKeyChecking=no \
    [email protected]  \
    'at 11:04 Dec 10' <myscript.sh
1

This is what worked for me if it comes to scheduling an at job. example of scheduling a shutdown:

sshpass -p "passw" ssh "[email protected]" -o StrictHostKeyChecking=no **"echo shutdown -h now | at 13:35 Dec 13"**

And this works from a shell script, example of making a file:

at 13:14 Dec 13 <<EOF
touch /tmp/atran3
EOF

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .