Operating System - Linux
1820389 Members
3476 Online
109623 Solutions
New Discussion юеВ

ssh command within script gives "select: Invalid argument" error.

 
erics_1
Honored Contributor

ssh command within script gives "select: Invalid argument" error.

Good Morning,

I have written a script to keep a dmz'd ftp server synced with one behind a firewall. The script runs fine via command line but has problems with one of the commands when run from cron. The script runs on a sco box using rsync and ssh to connect to an hpux 11.11 system. Here is the command that fails:

if [ `ssh -l root hostname ls /$path/$to/$list | wc -l` -gt 0 ]
then
rsync ....

debugging info returns the following
select: Invalid argument
+ [ 0 -gt 0 ]

I've set PATH as well as sourcing /etc/profile and /root/.profile within the script. No luck. Scripting is not my forte. I would greatly appreciate any insight!

Thanks,
Eric
10 REPLIES 10
Denver Osborn
Honored Contributor

Re: ssh command within script gives "select: Invalid argument" error.

Hey Eric,

can you attach the script being kicked off via cron?

Have you also looked at getting some debug output from ssh to see that ssh isn't the problem...

-denver
TwoProc
Honored Contributor

Re: ssh command within script gives "select: Invalid argument" error.

Eric,

Probably a path error from cron for the "ssh" command. Try using the full path to ssh.

Also, I generally surround the command string in an ssh command with "quotes" and have more sucess with that.

We are the people our parents warned us about --Jimmy Buffett
Stephen Keane
Honored Contributor

Re: ssh command within script gives "select: Invalid argument" error.

Which version of ssh are you running?
This is a known "feature" of earlier implementations of ssh, and usually the command is exected correctly (which is why ssh returns zero) so it's an irritant rather than a problem.
Denver Osborn
Honored Contributor

Re: ssh command within script gives "select: Invalid argument" error.

doh, noticed back tics...

instead of:
if [ `ssh -l root hostname ls /$path/$to/$list | wc -l` -gt 0 ]
then
rsync...
fi

how about...

if [ "$(ssh -l root hostname 'ls /path |wc -l' 2>/dev/null)" -gt 0 ]
then
rsync...
fi

Hope this helps,
-denver
Doug O'Leary
Honored Contributor

Re: ssh command within script gives "select: Invalid argument" error.

Hey;

Silly question of the week: When running from the command line, does your ssh ask for a password/phrase and/or is it using a ssh agent?

If so, you'll need to set up a null passphrased alternate identity, then change the ssh command to:

ssh -i ${alt_id} -l root ...

HTH;

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
erics_1
Honored Contributor

Re: ssh command within script gives "select: Invalid argument" error.

All,

Thanks for the input thus far. ssh version is 3.0.2 on SCO. Attached is a modified script to protect the innocent. I'm trying Denver's suggestion now.

Thanks,
Eric
erics_1
Honored Contributor

Re: ssh command within script gives "select: Invalid argument" error.

Doug,

I have public keys setup to allow ssh and rsync across without password/phrase. Denver, I tried your syntax but it looks like the script is just hanging there. I do see several errors in the dest. system's syslog:

sshd[2953]: error: getsockname failed: Invalid argument

Thoughts?

Eric
Denver Osborn
Honored Contributor

Re: ssh command within script gives "select: Invalid argument" error.

The other thing pointed out by Doug is that the script does not use your ssh-key. If it runs well from the command line then the diff there is being that the keys are possibly being used.

if you have an ssh-key that uses a passphrase, you need to cache the passprase w/ ssh-agent and tell the script to use the already running ssh-agent... or keep it simple and setup a key w/ out a passphrase and limit access of that key from directive s prepended to the key in .authorized_keys file.

so could be your orignal script was fine afterall, just failed in cron because it didn't use the ssh-agent you had running when the script was manually kicked off.

-denver
Denver Osborn
Honored Contributor

Re: ssh command within script gives "select: Invalid argument" error.

doh.

go back to your original script... do what doug said. :)

this: ssh -l root hostname

to this: ssh -i /path/to/your__passwordless_key -l root hostname


if all else fails, also use the "-vvv" w/the above ssh syntax change to see what's happening.
RAC_1
Honored Contributor

Re: ssh command within script gives "select: Invalid argument" error.

sshd[2953]: error: getsockname failed: Invalid argument
Makes me think, Any firewalls in between?? The sshd by default listens to port 22. Is that port open in firewall??

Also you can run sshd -ddd and get more verbose details about error message.

Also as you are running through cron, make sure that you have all required variables set properly. Intentionally cron environment is very sparse.
There is no substitute to HARDWORK