On Tue, Sep 07, 2010 at 12:21:56PM -0500, Todd T. Fries wrote:
> Neither of the above solutions provide the same output.
> 
> Sorry, the requirement is to `notice' we are on a new line if an error occurs,
> and only do the final echo if we are not on a new line at the end.

Another shot at this using mktemp to save the ssh-keygen output to a
temporary file.  The output looks a little cleaner, IMHO.


ssh_keys=0

for _type in dsa ecdsa rsa rsa1; do
        if [ "${_type}" = "rsa1" ]; then
                _key='/etc/ssh/ssh_host_key'
        else
                _key="/etc/ssh/ssh_host_${_type}_key"
        fi

        _name=`echo ${_type} | tr a-z A-Z`

        if [ ! -f "${_key}" ]; then
                if [ "${ssh_keys}" -eq 0 ]; then
                        echo -n 'ssh-keygen: generating new host key:'
                        ssh_keys=1
                fi

                _tmp=`mktemp /tmp/_keygen.XXXXXXXXXX`

                echo -n " ${_name}"
                ssh-keygen -q -t "${_type}" -f "${_key}" -N '' > ${_tmp} 2>&1
                if [ $? -ne 0 ]; then
                        echo
                        cat "${_tmp}"
                        ssh_keys=0
                fi

                rm -f ${_tmp}
        fi
done

if [ "${ssh_keys}" -eq 1 ]; then
        echo '.'
fi

Reply via email to