简体   繁体   中英

Bash script automation : Involve copying file from source to dest, executing script in destination and copy result from dest to surce

I have a requirement to create an automation script which will do the below stuff in given order :

  1. Copy some script & XML from source to destination.
  2. Run the script in the destination
  3. 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

Your solution is ok. You could consider to use sshfs to mount remote directory on src machine and use command like this file was on src machine.

example:

sudo sshfs -o allow_other,nonempty user@10.1.2.3:/project /project

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM