First you need to get the password from the user or set the password in a variable.
read -s -p "Enter remote user password: " usrpwd
This prompts the user to enter the password, without echoing to the screen and stores it in $usrpwd.
Now we can ssh to the remote server and run a command via sudo.
Here I'm just running date but you can do anything.
ssh raspberrypi sudo -S <<< $usrpwd date
james@raspberrypi's password:If you incorporate this with my previous blog on SSH you can automate the logging into a remote server and running scripts.
[sudo] password for james: Wed 6 Mar 15:44:44 GMT 2019
As with all of this stuff the easier you make it for yourself the easier it is for somebody else to destroy your servers.