0

I am running a shell script(which contains several UNIX commands) from DEV environment. Now in this shell script i need to write a unix command to connect to a QA environment and go to a particular path over there to check for some files.

i am using below command to connect to QA environment through script:

ssh QA      ---- To connect to QA environment
cd a/b/c    ----- To execute this command under QA environment.

when i am executing a script, it is then asking me for a password to connect to QA environment and after entering password i am able to connect to QA. BUT THE COMMAND 'cd a/b/c' IS NOT GETTING EXECUTED IN QA AFTER THAT.

Please suggest which command should i use in the unix script to connect to QA environment and execute some unix commands over there in a same script?

Floris
  • 45,857
  • 6
  • 70
  • 122

1 Answers1

1

The syntax for executing a command on the host connected to with ssh is:

ssh user@host command

To execute command on the host and return:

ssh user@host 'cd /etc/ && echo fstab'

To execute command and stay connected to the host:

ssh user@host -t 'cd /etc && bash -i'

See man ssh for reference on your system.

  • Agree: the && is quite important to stop attempting execute if the cd failed. You could also "cd && execute || echo trouble" to get a specific message if either failed. – Gilbert Dec 14 '13 at 13:13
  • Thanks people..above code is working.. but the real command which i want to execute is 'air tag' the above code is working perfectly for ls and cd commands. but when i am trying 'air tag a.save' its showing me an error that 'ksh: air: not found' – user3095778 Dec 14 '13 at 14:19
  • @user3095778 That error means the `air` command either isn't installed or can't be found in the current path on the remote host. –  Dec 16 '13 at 09:52