Am trying to login into a remote server, and I want to function to be executed on remote server. Can I send the function name including in ssh command.
Asked
Active
Viewed 105 times
2
-
You mean a function gets executed once you logged in? What function? – NullDev Mar 24 '17 at 12:26
1 Answers
0
Of course you can. the below is the appropriate syntax for it. You can run one or more commands separated by semicolon.
ssh -n -l yourusername yourremoteserver "pwd; hostname; netstat -tupln | tail -5"
Let me know if this works for you.
Note - Be aware that in will ask for your password. If you are planning to use this inside a script, you should copy your keys to the remote server you are trying to run the command on, and only then it will authenticate using the keys instead of prompting for your password. Copy the same is a straight forward process, really simple, you can see the steps here:
https://askubuntu.com/questions/4830/easiest-way-to-copy-ssh-keys-to-another-machine

Community
- 1
- 1

Matias Barrios
- 4,674
- 3
- 22
- 49