I want to use a shell script to pull a file from another server. I have written a script where i can do this but i want the script to work non-interactively so that it doesn't prompt me for the password and works automatically if i hard-code the same and let the script have what it needs.
I have done this before for FTP however, in out new servers the FTP connections are blocked and we can use only SCP or SFTP. My earlier script was something like this which used to work with FTP and did the job well without asking for the password:
#!/bin/bash -vx ftp -in 100.XXX.XXX.XX<<END_SCRIPT quote USER username quote PASS password bin prompt off cd /directory/in/remote/host lcd /directory/in/local/machine mget * bye END_SCRIPT I tried the similar for SFTP in a script and it works for Interactive mode but like FTP i am not able to use the non-interactive options for SFTP. Following is my code to fetch particular files from the remote machine:
#!/bin/bash -vx path="/tmp/testanks" sftp [email protected] <<EOT cd $path get Bharti* quit EOT How can i change the above code in a way that i could provide this script the username and password to make it non-interactive.
I understand that providing a hard-coded password is a security concern but right now i am concerned more about fetching the files immediately. I would really appreciate if i could get the secured ways of doing it as well along with the answer i desire.