My objective: Automate scp from one server to another taking inputs from user Challenge: I can not setup ssh authorized host equivalence between the servers because one user having access to target will also get access to source server So, I need to setup legacy method of providing password when prompted and then do scp.
Here is my code
L_SRC_SID=source
L_SID=target
MOUNT_POINT=app07
SERVICE_PASS=some$value
APP_SERVER_1=hostname
SRC_MOUNT_POINT=app01
#And now transfer the file over
/usr/bin/expect -c "
set timeout 1
cd /$MOUNT_POINT/$L_SID/apps
spawn scp -pr * apps@$APP_SERVER_1:/$SRC_MOUNT_POINT/$L_SRC_SID/apps .
expect yes/no { send yes\r ; exp_continue }
expect password: { send $SERVICE_PASS\r }
expect 100%
sleep 1
exit
"
exit
Challenges: 1. I am unable to assign some$value value to variable SERVICE_PASS 2. How to make the expect send script work using such a variable that has $ character in the password. It is failing with the below error.
password: can't read "value": no such variable
Any help is appreciated
I have changed the code as per suggestions, but still getting the same error
L_SRC_SID=source
L_SID=target
MOUNT_POINT=app07
SERVICE_PASS='some$value'
APP_SERVER_1=hostname
SRC_MOUNT_POINT=app01
#And now transfer the file over
/usr/bin/expect -c "
set timeout 1
cd /$MOUNT_POINT/$L_SID/apps
spawn scp -pr * apps@$APP_SERVER_1:/$SRC_MOUNT_POINT/$L_SRC_SID/apps .
expect yes/no { send yes\r ; exp_continue }
expect password: { send $SERVICE_PASS\r }
expect 100%
sleep 1
exit
"
exit
Here is the complete error.
password: can't read "value": no such variable
while executing
"send some$value\r "
invoked from within
"expect password: { send some$value\r }"