Here is simple script to copy using scp and expect ,
We are creating a simple script on the fly and run that script
cat > /tmp/copy_from_remote.sh << EOF
#!/usr/bin/expect
set timeout 10
log_user 0
spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $REMOTE_CREDENTIAL_USERNAME@$host_name :$
expect "*?assword"
send "$CREDENTIAL_PASSWORD\r"
expect "*100\%*\r"
EOF
chmod 777 /tmp/copy_from_remote.sh
sh /tmp/copy_from_remote.sh
Once script is ready need to run .
For details we can add exp_internal 1 in the expect script
Need to disable host key checking and known host file .
We are creating a simple script on the fly and run that script
cat > /tmp/copy_from_remote.sh << EOF
#!/usr/bin/expect
set timeout 10
log_user 0
spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $REMOTE_CREDENTIAL_USERNAME@$host_name :$
expect "*?assword"
send "$CREDENTIAL_PASSWORD\r"
expect "*100\%*\r"
EOF
chmod 777 /tmp/copy_from_remote.sh
sh /tmp/copy_from_remote.sh
Once script is ready need to run .
For details we can add exp_internal 1 in the expect script
Need to disable host key checking and known host file .