0

I need to emulate the following with a script which is invoked by a web service run from a Linux server:

  • Access remote AIX server via SSH
  • Log into an Intersystems Cache instance (if that's unfamiliar, pretend we're loading an interactive Python or Ruby [irb] environment)
  • Execute commands
  • Execute more commands depending on output of previous commands
  • Log all input to and output from this environment

This is fairly trivial to do in C# with the SSH.NET library. Open a shellstream to the remote host, attach a StreamReader and StreamWriter, then send input to the SSH connection via StreamWriter and read output from it via StreamReader.

How should I go about this on a Linux server with ssh? I am experimenting with screen, but it seems more designed more for human-interactive use than by scripts, and I wonder if I am barking up the wrong tree.

I don't have control over what's installed on the AIX server. I might be able to get things installed there but no guarantees.

Much later edit: possible solutions include pexpect/pxssh (Python), paramiko (also Python)

2
  • 2
    did you check expect or pexpect(python) ?
    – chaput
    Commented Mar 25, 2014 at 15:24
  • 1
    While this question is perfectly on topic and welcome to stay here, there are a lot more Unix users on our sister site Unix & Linux. If you don't get a useful answer here after a while, consider flagging this for moderator attention and asking them to migrate it over.
    – terdon
    Commented Mar 25, 2014 at 17:30

1 Answer 1

0

Yes, screen is not the way. I don't know about cache but can you write a script for it or do you need the interactive shell? If you can write a script and save it on the AIX machine, you should be able to do

ssh [email protected] /path/to/cache_script

Another approach would be to use expect which is also available on AIX but I can't give you more details without knowing the commands you need to run. In any case, expect allows you to send commands and respond to output, interacting with an interactive shell in a non-interactive way.

1
  • pexpect and pxssh look like they'll be magic for this and test well. No need to run anything (even expect) on the remote host. Thanks for both people's replies.
    – wilee
    Commented Mar 26, 2014 at 16:20

You must log in to answer this question.

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