Next: , Previous: , Up: sendmail script   [Contents][Index]


A.6.4 Reading authentication credentials from file

The only way the script has to acquire the user name and password to log into the remote server, is by reading the authinfo file. By default, its pathname is $HOME/.mbfl-authinfo, it can be overridden with the --auth-info option.

Its format is a simplified version of the netrc file format: blank lines are ignored, lines starting with a # character are comments, lines starting with machine are host records.

Each record must have the format:

machine <hostname> login <user-name> password <pass-word>

for example:

machine smtp.gmail.com login one@gmail.com password abcdefghilm
machine relay.poste.it login two@poste.it  password 0123456789

so that we can extract a record with the following script:

file=~/.mbfl-authinfo
host=poste
username=marco

rex='^[ \t]*'
rex+='machine[ \t]\+.*%s.*[ \t]\+'
rex+='login[ \t]\+.*%s.*[ \t]\+'
rex+='password[ \t]\+.*'
rex+='[ \t]*$'
rex=$(printf "$rex" $host $username)

line=$(grep "$rex" $file)
set -- $line
echo machine  $2
echo username $4
echo password $6

currently sendmail-mbfl.sh parses the file using the =~ regular expressions operator.

The host name and the user name are selected by the command line options --host and --username. Notice that the values for these options can be substrings of the values in the authinfo file.


Next: , Previous: , Up: sendmail script   [Contents][Index]

This document describes version 3.0.0-devel.0 of Marcos Bash Functions Library.