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?

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
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 That error means the air command either isn't installed or can't be found in the current path on the remote host.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.