Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want copy files from one linux to other linux machine (local) using sftp daily. So i have written a shell script to perform this but it prompts password when executed though i have hardcoded the pwd in the script. I found that by exchanging keys i perform this but please let me know is there any other solution
Find the script below
#!/bin/sh
# sample automatic ftp script to dump a file
USER=<user_name>
PASSWORD=<pwd>
HOST=<server_name>
TGT_DIR=$BASE_DIR/FromCheetah_automation
COA_DIR=$BASE_DIR/FromCheetah_bkp/archive
LDR_DIR=$BASE_DIR/FromCheetah_bkp/archive/Loader_Files
UNSUB_DIR=$BASE_DIR/FromCheetah_bkp/archive/Unsubs_Files
dt=`date +%Y%m%d`
fldt=`date --date "$dt 1 days ago" +%Y%m%d`
lgdt=`date +%Y%m`
echo "today is $dt"
echo "File dat is $fldt"
sftp $USER@$HOST << EOF
$PASSOWRD
cd working_dir
mget iid_keys_$fldt*.dat.txt $TGT_DIR >> $LOG_DIR/emailftp_log_$lgdt.log
mget data_$fldt*.dat.txt $TGT_DIR >> $LOG_DIR/emailftp_log_$lgdt.log
quit
EOF
Other methods to perform this task involve scp and rsync. Of all the methods discussed here so far, rsync will get you the best performance. Both scp and rsync are easier to use in a cron job than ftp/sftp, too. The commands will fit on a single line.
All three can be used with key exchange authorization, eliminating the need for a password.
also sftp is for human prompts (e.g.- please enter user name, please enter password, please enter local file, please enter remote file, ...)
scp is for automated machines(e.g.- scp user1@server1:/path/to/source user2@server2:/path/to/dest)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.