Hello, I'm new to scripting so, sorry if this is a dumb question. What's the best way to execute a .sh file remotely? I want to log into server "b" from server "a" & run a script. "./scriptname.sh". At this point, all I'm looking to do is a simple ls -la > output.txt within the script to capture the current contents of the directory that I navigated to. Is there a way to accomplish this?
Thanks
You do not need to enclose the ls command in a separate script file. Try this...
ssh user@b 'ls -la > output.txt'
where user is the id on the destination system (b) under which you want to connect and execute the command. The command should execute and the output.txt file should appear in the home directory for user.
You can include just about any command, including script files within the single quotes. Just make sure the script file is executable and either in the path or is accessed via the full path name. You might need to use something like:
ssh user@b 'sh ~/scriptname.sh'
Also one question from my side.Is it possible to include the password in the command?
If you dont want password to be asked you can use public authentication .
using
ssh-keygen command.