Our Linux setup doesn't have keygen configured for password less authentication. Hence I am supposed to use only EXPECT
for password less authentication in a shell script.
/usr/bin/expect<<EOF >> ${LOG_FILE}set timeout 60spawn sftp ${EWS_USER}@${EWS_HOST}:${TGT_DIR}expect "*?assword:"send "$password\r"expect "sftp>"send "put $local_dir/$line\r"expect "sftp>"send "bye\r"expect EOFEOF filename=$(basename "$line") # echo "File Name: $filename" #Calculate the MD5Sum locally. local_md5sum=$(md5sum "$line") #echo "Local MD5Sum: ${local_md5sum}" #Calculate the MD5sum in remote machine remote_md5sum=$(ssh ${EWS_USER}@${EWS_HOST} "cd '$TGT_DIR' ; find -name '$filename' -exec md5sum {} \;"< /dev/null) #echo "Remote MD5Sum: ${remote_md5sum}"LOCAL_SUM=`echo ${local_md5sum} | awk {'print $1'}`REMOTE_SUM=`echo ${remote_md5sum} | awk {'print $1'}`echo $LOCAL_SUMecho $REMOTE_SUMif [ "${LOCAL_SUM}" != "${REMOTE_SUM}" ]then echo "SFTP Successfull"else echo "SFTP Unsuccessfull"fi
I know how to use EXPECT
in the below place
sftp ${EWS_USER}@${EWS_HOST} << EOF >> ${LOG_NAME}put ${LOCAL_DIR}/${line} ${TGT_DIR}/${line}EOF
But any idea how to use EXPECT here in the below scenario to make the connection password less?
remote_md5sum=$(ssh ${EWS_USER}@${EWS_HOST} "cd '$TGT_DIR' ; find -name '$filename' -exec md5sum {} \;"< /dev/null)