0

Haven't found something that addresses my problem specifically.. Writing bash script to quickly get into a box, print what I want to see, and then leave the box if possible.

#!/bin/bash

ssh user@boxname ; cd /data/

This gets me into the box, but neither the echo, nor any directory change commands I input seem to run. I've also tried..

ssh user@boxname && cd /data/

or simply

ssh user@boxname
echo "im in"

I have a little experience with bash scripting, but I'm not sure why commands aren't being executed after ssh'ing into the box. Any direction and/or explanation would be greatly appreciated.

Squid
  • 5
  • 1
  • When you run `cmd1; cmd2`, `cmd2` doesn't run until `cmd1` exits. In this case, that means the `cd` or the `echo` doesn't happen until after `ssh` is no longer running. – Charles Duffy Mar 03 '20 at 19:15
  • When you run `ssh` and press enter at a prompt, it's not that your existing shell is communicating with the remote machine; instead, you're now typing content *into the copy of ssh* instead of into your existing shell. When you run a script, that entire script is executed by *one* shell. It can start other shells and even connect things to their stdin, but you need to make that explicit. – Charles Duffy Mar 03 '20 at 19:16

0 Answers0