0

How to execute command with bash script inside Ubuntu, which was started with bash script?

for example with ssh I'm accessing ubuntu. How to run command inside opened ubuntu. If I write it in bash script after ssh command it will get executed as soon as I exit out of this environment.

How to execute bash script inside this environment?

3 Answers 3

1

Is it possible that you are asking how to start a command on a remote machine with ssh? That would be:

ssh user@hostname your_script_name-here

There are some command line args that affect the remote command, like -f. If this is indeed what you are asking about then the ssh man page is mostly your friend.

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

Comments

1

Yes it is very much easy,

   you need to install Secure Shell (SSH) / Secure FTP (SFTP) Server in Ubuntu. then go through the recommended level of security settings to run an SSH server to be able to execute terminal commands or transfer files securely.

for reference check out the example video and this tutorial as well.

1 Comment

thanks, but maybe my question wasn't pretty clear. It's the following: my first command in bash script is: "ssh [email protected]". when I run this command I'm accessing Ubuntu. Then inside ubuntu I want to run "ls" command. But if I type this command inside bash script it gets executed after i exit my ubuntu server. I need it to be executed inside.
0

I don't really understand what you want to do. Do you want to bash a script for example ./main.py so that the script doesn't stop when you leave the SSH-connection? If that's your question, try ./main.py & !

2 Comments

my first command in bash script is: "ssh [email protected]". when I run this command I'm accessing Ubuntu. Then inside ubuntu I want to run "ls" command. But if I type this command inside bash script it gets executed after i exit my ubuntu server. I need it to be executed inside.
The ls command just prints something (the objects in your current folder) in the console. What do you mean with it gets executed when you executed? can you please post your complete Code and what you want to do??

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.