I use linux based operating system. let's say, I have a server contain 10 files like tmp1 .... tmp10, and I want to copy three specific files to my local machine, let's say, tmp3, tmp7 and tmp10. In this case I have to use the "scp-command" three times, where I have to enter the password also three times. the problem is, that I have to do this process so often, so I "wrote" the script below. My PROBLEM is, that the script runs without any error message, but the files are not copied.
echo "insert path of source:" #prompt to enter the path of files you want to copy
read SOURCE # saving the path in the variable SOURCE
echo "insert path of target:" #prompt to enter the path, where you want to past the copied files
read TARGET # saving the path in the variable SOURCE
echo "Insert the port" # prompt to enter the port of the server
read port # saving the port in the variable PORT
echo "Password?" # asking for password
read -s -a PASSWORD # saving the password in the variable PASSWORD
x=(tmp1 tmp2) # An array contains the files i want to copy.
for i in "${x[@]}" # A for-loop to copy each of the files in the array (x) from the SOURCE to the TARGET
do
echo "the file $i" # just to check if the array has been read.
#!/usr/bin/expect -f # to read the expect-programm
expect -c "
spawn /usr/bin/scp -P $prot $SOURCE/$i $TARGET
expect {
"Password:" { send $PASSWORD\r\n; interact }
eof { exit }
}
exit
"
done # End of the for-loop
PASSWORD=0 # To delete the variable PASSWORD
thank you in advance!!