3

I want to be able to just ssh to a server where I cannot modify profiles and set up the environment with several commands before getting the usual interactive session.

Any ideas?

I've been using an expect script with an "interact" command at the end - which works for most things but is clumsy and breaks some console apps. Also been extermienting with empty-expect and socat. Any other suggestions?

Mat
  • 202,337
  • 40
  • 393
  • 406
Paul Hedderly
  • 3,813
  • 2
  • 18
  • 12
  • Oops, just saw you cannot edit the profile. – ott-- Oct 05 '11 at 12:02
  • This is more or less what I want to acheive: http://stackoverflow.com/questions/1633750/ssh-with-command-plus-the-shell/1634179#1634179 but it still breaks some things. – Paul Hedderly Oct 05 '11 at 12:07

1 Answers1

3

If you're able to write somewhere on the filesystem, you may be able to invoke bash with a custom rc file like this:

ssh me@example.com -t bash --rcfile /home/user/my_private_profile -i

Note that this appears to only work for interactive shell, not login shells. The -t option to ssh makes it allocate a pty even though you're specifying a command.

If you can't write to the filesystem anywhere, you could use a subshell to supply a named pipe as the rcfile:

$ ssh ares -t "bash --rcfile <(echo 'FOO=foo';echo 'BAR=bar') -i"
axa@ares:~$ echo $FOO
foo
axa@ares:~$ echo $BAR
bar
Andrew Aylett
  • 39,182
  • 5
  • 68
  • 95