Ok, if someone needs a solution
you can try this (with expect
)
#!/usr/bin/expect -f
set ip [lindex $argv 0]
set login [lindex $argv 1]
set password [lindex $argv 2]
set cmd [lindex $argv 3]
set timeout -1
spawn $env(SHELL)
match_max 100000
send -- "ssh $login@$ip\r"
expect {
"connecting (yes/no)?" {send -- "yes\r"}
"assword:" {send -- "$password\r"}
}
expect {
"assword:" {send -- "$password\r"}
">" {}
}
expect ">"
send -- "$cmd\r"
expect ">"
send -- "exit\r"
expect "closed"
send -- "exit\r"
expect eof
Then you just need to call the script like this (of course you need expect command)
./script user@10.10.10.10 ls
or
./script user@10.10.10.10 "ls;cd..;ls" for multiple commands