Last active
April 30, 2023 20:36
-
-
Save normanr/fdb8b73b536a0b4857016ee3408bbf29 to your computer and use it in GitHub Desktop.
read sftp password from .netrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: SSH_ASKPASS_REQUIRE=force SSH_ASKPASS=netrc-askpass sftp ... | |
if [[ $1 =~ ([[:graph:]]+)@([[:graph:]]+)\'s\ password: ]]; then | |
USER="${BASH_REMATCH[1]}" | |
HOST="${BASH_REMATCH[2]}" | |
state=token | |
while read -a WORDS; do | |
for WORD in ${WORDS[@]}; do | |
case $state in | |
token) | |
case "${WORD}" in | |
machine) | |
state=machine | |
;; | |
login) | |
state=login | |
;; | |
password) | |
state=password | |
;; | |
esac | |
;; | |
machine) | |
machine="${WORD}" | |
state=token | |
;; | |
login) | |
login="${WORD}" | |
state=token | |
;; | |
password) | |
password="${WORD}" | |
state=token | |
if [[ "$machine" == "$HOST" ]] && [[ "$login" == "$USER" ]]; then | |
echo "$password" | |
exit 0 | |
fi | |
;; | |
esac | |
done | |
done < ~/.netrc | |
fi | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment