Hello I am creating a script for our job that will pull the files from remote server.
- The user will input the file names
- And then using ssh command I will list the file in order for the user to check it's size first before pulling.
- If the user's answer=y then it will proceed on the sftp.
My problem is when performing the ssh command it will ask for a password and will ask again when doing the sftp.
I can't use sshpass as it is blocked by the admin.
#!/bin/bash
read -p "UserID: " UserID
read -p "Error file: " file1
read -p "Log file: " file2
ssh $UserID@127.0.0.1 "ls -ltr /logs/$file1 && ls -ltr /logs/$file2"
read -p "Please check the file size, do you want to proceed? (y/n): " choice
if [[ "$choice" == "y" ]]
then
sftp $UserID@127.0.0.1 << EOF
get /logs/$file1 /home/
get /logs/$file2 /home/
EOF
else
echo "Exiting..."
exit
fi
I tried using sshpass to store the password but it is blocked (permission denied) so I am looking for alternatives.