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

Hi Bart,

I am using the same version (the x450e switches I am using cannot run newer EXOS versions). When testing this with the EXOS-VM version 21.1.14, ssh commands work fine with STDIN redirected from /dev/null, so inbetween those EXOS version something was changed. It might be a side effect of the newer SSH code in 21.1.

To summarize the situation for EXOS 15.3:
  • SSH commands work fine from an interactive shell (e.g. terminal window)
  • SSH commands with STDIN redirected from /dev/null do not work from an interactive shell (neither with ssh -n nor ssh SSH commands from a script started via cron do not work (here STDIN is redirected from /dev/null by cron)
  • expect can be used to work around this issue (e.g. the original TCL based expect, or a Perl extpect module, or one for Python)
I have successfully tested a simple expect script with EXOS 15.3 today. Expect provides the input to SSH on STDIN.

With EXOS version 21.1, SSH commands work even with STDIN redirected from /dev/null, e.g. when used via cron.

Best regards,
Erik

Erik,

I'm using on all my switches:
Image : ExtremeXOS version 15.3.5.2 v1535b2-patch1-9 by release-manager
on Fri Dec 11 12:07:39 EST 2015
BootROM : 1.0.3.5

I get the same result as you do with running my_script
Which version are you running?

Bart_Wallace
New Contributor
I have the same problem using a perl script. We are using the script to grab the configuration on a nightly basis, then commit the files to git for version control, backup, archive, etc.

The script executes perfectly if I run it manually from command line. However, running the same script within cron and it fails. I have a user account using a ssh user-key added to the admin account on the switch.

Here's the command executing by the script:
"ssh -oStrictHostKeyChecking=no admin\@$xxrip upload configuration $tftpserver $xxrname.xsf" where $xxrip, $tftpserver and $xxrname are passed into the command from a hash.

I've tried adding the -t -t option but no change.

My error code from the perl script for this command is 255, both from running the script manually, or through cron - I'm guessing 255 is "all ok" as the script works just fine running manually. However, the configuration file is never uploaded to my tftp server when running the script through cron.

I contacted tech support and opened a case (#01203422), but they've passed me off with the following:
I wanted to follow up with you on this case. Unfortunately at this point there's nothing more we can do to troubleshoot this as this is an issue with KRON and not the switch itself. Have you tried to contact support for the scheduler?"

I'm looking for any help with this. I can share my perl script and git methods with anyone that is interested. Having a copy of the latest configuration(s) has saved me a few times.

Erik_Auerswald
Contributor II
Getting closer...

I have tested with an X450e-24p with EXOS 15.3.5.2, there I see the reported problem. I do not receive the switch output if the command is started from cron or with STDIN redirected from /dev/null. This seems to be an issue with the older firmware. 😞

Iván_García_Díe
New Contributor
I dont understand why it fails in my case. And only with this device.

But finally, trying another ways i succeeded using expect. The output of the command is saved in the expect log.

Thanks

GTM-P2G8KFN