I have a requirement to create an automation script which will do the below stuff in given order :
- Copy some script & XML from source to destination.
- Run the script in the destination
- Copy the results (which are files) from the destination to source.
I am using "expect" to copy files from source to destination. Then I am trying to establish ssh connection towards the destination and execute script in the destination. Once we have result generated, I will again copy files using "expect" but this time from destination to source.
I was wondering if there is any better way of doing the same.
Code to copy the files using "expect" as I need to pass password for scp :
#!/usr/bin/expect -f
set from [lindex $argv 0]
set to [lindex $argv 1]
set pass [lindex $argv 2]
puts "$from, $to and $pass ."
# connect via scp
spawn sudo scp -v -r $from $to
#######################
expect {
-re ".*es.*o.*" {
exp_send "yes\r"
exp_continue
}
-re ".*sword.*" {
exp_send $pass\n
}
}
interact