1

How to execute a method on remote machine connecting with sshpass Following is the code:

#!/bin/bash
checkfunctioncall() {
cd "/home/user"
mkdir "remotecalltest"

}

sshpass -p "$serverpwd" ssh "$serveruser"@"$serverip" checkfunctioncall

but I am getting below error:

bash: checkfunctioncall: command not found

Please suggest

I am specifically looking for solution with sshpass, as I need to login to remote server with a password

Saurabh Mehta
  • 91
  • 1
  • 2
  • 9
  • 1
    Possible duplicate of [Shell script: Run function from script over ssh](https://stackoverflow.com/questions/22107610/shell-script-run-function-from-script-over-ssh) – Andrew Jun 08 '17 at 15:20
  • @Andrew: No, Its not, I already saw this post, but I am specifically looking for solution with sshpass, as I need to login to remote server with a password – Saurabh Mehta Jun 08 '17 at 15:25
  • You just can't execute locally defined function, because the remote machine knows nothing about it. Write the script you want to run, copy it to the remote machine and then run it. – nsilent22 Jun 08 '17 at 19:55

1 Answers1

0

I think this will remove the above error.

sshpass -p "$serverpwd" ssh "$serveruser"@"$serverip" << EOSSH
checkfunctioncall(){
cd "/home/user"
mkdir "remotecalltest"
}
checkfunctioncall
EOSSH
skr
  • 2,146
  • 19
  • 22