I want to ssh to multiple server using bash script and automate this script using crontab. I use "expect" to ssh to multiple server because of authentication need. But, I don't know how to copy the file in destination server using SFTP to my server. Can someone give me some clue for this problem.
Here is my code to SSH to multiple server (in this case I make tunneling to server destination):
/home/users/script/expect.sh 45108 username password "command"
/home/users/script/expect.sh 45109 username password "command"
#45108 is port for tunneling, username and password is using like in shell terminal (ssh username@ipadd -p $server)
and this is the expect script that I use:
#!/usr/bin/expect
set timeout 10
set node [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set command [lindex $argv 3]
spawn ssh $username@localhost -p $node
expect {
"(yes/no)?"
{
send "yes\n"
expect "*assword:" { send "$password\n"}
}
"*assword:" { send "$password\n" }
}
expect {
"*#" { send "$command\n" }
}
expect {
"*#" { send "exit\n" }
}
expect eof
Thank you