views:

278

answers:

4

Is it possible to have a Perl script run shell aliases? I am running into a situation where we've got a Perl module I don't have access to modify and one of the things it does is logs into multiple servers via SSH to run some commands remotely. Sadly some of the systems (which I also don't have access to modify) have a buggy SSH server that will disconnect as soon as my system tries to send an SSH public key. I have the SSH agent running because I need it to connect to some other servers.

My initial solution was to set up an alias to set ssh to ssh -o PubkeyAuthentication=no, but Perl runs the ssh binary it finds in the PATH instead of trying to use the alias.

It looks like the only solutions are disable the SSH agent while I am connecting to the problem servers or override the Perl module that does the actual connection.

+5  A: 

Perhaps you could put a command called ssh in PATH ahead of the ssh which runs ssh as you want it to be run.

Kinopiko
Great idea! Why didn't I think of that before? Anyway, apparently great minds think alike - I got two identical answers at the same time.
Kenny Drobnack
+3  A: 

Why don't you skip the alias and just create a shell script called ssh in a directory somewhere, then change the path to put that directory before the one containing the real ssh?

I had to do this recently with iostat because the new version output a different format that a third-party product couldn't handle (it scanned the output to generate a report).

I just created an iostat shell script which called the real iostat (with hardcoded path, but you could be more sophisticated), passing the output through an awk script to massage it into the original format. Then, I changed the path for the third-party program and it started working fine.

paxdiablo
+4  A: 

Alter the PATH before you run the perl script, or use this in your .ssh/config

Host *
  PubkeyAuthentication no
codehead
I would think this would be the preferred way if you had specific hosts that were problematic. Then instead of * you could put the host (or a mask matching your problem hosts). Documentation for ~/.ssh/config is in ssh_config(5).
opello
After messing with things, I think the .ssh/config option will work out better. I'm connnecting to all the problem hosts via IP address (been told that DNS isn't reliable in this case - a completely different issue). But the systems that work, I am connecting using the hostname. So Host 10.* PubkeyAuthentication no should resolve the issue quite nicely.
Kenny Drobnack
A: 

You could declare a function in .bashrc (or .profile or whatever) with that name. It could look like this (might break):

function ssh {
  /usr/bin/ssh -o PubkeyAuthentication=no "$@"
}

But using a config file might be the best solution in your case.

dz