cancel
Showing results forĀ 
Search instead forĀ 
Did you mean:Ā 

Impossible to get output of remote ssh commands via cron

Impossible to get output of remote ssh commands via cron

IvƔn_Garcƭa_Dƭe
New Contributor
Hello,

I have made a bash script to get ipstats of several devices, and i have a problem with my X450a-48t, the script works fine if i execute it manually, but in crontab no output, i think because in cron no tty is allocated.

Example script:

#!/bin/bash

ssh -o "StrictHostKeyChecking no" admin@10.26.196.189 "show ipstats"

i have checked ssh with -t and -tt option, but doesn't work.

ĀæAny idea how to solve it? Āæanother possibility to get this stats remotely?

Regards,

Ivan

13 REPLIES 13

Erik_Auerswald
Contributor II
Hello Bart,

which version of EXOS do you use? In my testing older firmware versions did not work, while newer did.

Did you try to run your script with /dev/null as STDIN from a terminal window? That resulted in the same problem as running the command from cron for me.
$ my_script HTH,
Erik

Hi,

I have used the following simple script just to test the switch behavior with SSH via expect. The switches had my SSH key configured for admin access. The switch IP address needs to be adjusted, of course.
#! /usr/bin/expect -f spawn ssh admin@192.0.2.11 expect { {# } {send "show version\r"} } expect { {# } {send "exit\r"} }The expect script waits for the switch prompt (login w/o password handled via SSH), issues the command "show version", and logs off the switch after detecting the prompt again.

Br,
Erik

Bart,

I'm not in the office today, but I plan to add the script to this thread tomorrow.

Erik

Erik,

Thanks for the info. I'll look into expect perl modules. Can you provide the simple script you tested today so I can verify results?

Bart
GTM-P2G8KFN