2

I have a Bash alias for sending a command to my server like:

alias ssh=sshpass -p "Passw0rd!" ssh -p 9999 -q -oStrictHostKeyChecking=no [email protected] "some_command"

but I want to be able to enter different commands (instead of a predefined command between quotation marks) each time, with a prompt for my input. Is that possible with some function?

1

1 Answer 1

6

It's as easy as that:

myfunctionname(){
  sshpass -p "Passw0rd!" ssh -p 9999 -q -oStrictHostKeyChecking=no [email protected] "$@"
}

This defines a function myfunctionname which uses the arguments you give it as the command(s) for ssh. Example calls:

myfunctionname tree
myfunctionname "ls -l; hostname"
myfunctionname ls -l\; pwd         # remember quoting if doing that!

Put the function in your ~/.bashrc file to make it accessible from every new terminal.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .