This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

ssh-add stuck from time to time.


I'm using rsync in crontab to automate a periodic backup of some files
to a Debian server.

I'm trying to prevent the cron job from getting stuck when no
ssh-agent is actually alive. Here is my setup:

OS: Windows 8.1 64-bit
Cygwin: 64-bit 1.7.32

Relevant packages*:
- openssh 6.7p1-1
- keychain 2.7.1-1
- rsync 3.0.9-1
- cron 4.1-61
- bash 4.1.17-9

The crontab:
BACKUP_LOG_PATH=/home/kal/backup.log
*/1 * * * * /usr/bin/flock -n /tmp/my_backup.lck /home/kal/backup

The /home/kal/backup script:
#!/usr/bin/bash
# redirect stdout and stderr if BACKUP_LOG_PATH defined.
if [ "$BACKUP_LOG_PATH" ]; then
    exec > "$BACKUP_LOG_PATH" 2>&1
fi

keychain_file="/home/kal/.keychain/$HOSTNAME-sh"

if [ -r "$keychain_file" ]; then
    . /home/kal/.keychain/$HOSTNAME-sh
    if kill -0 "$SSH_AGENT_PID" && /usr/bin/ssh-add -l > /dev/null; then
        kdd=/cygdrive/e/final/
        if [ "$(ls "$kdd")" ]; then
            rsync -az --chmod=Dugo+rwx,Fugo+rw --remove-source-files
--exclude='bundle_version' "$kdd"*
kal@my.debian.server:/srv/datafiles/
            exit_status_1=$?
            if [ $exit_status_1 -ne 0 ]; then
                echo "[`date`]: failure ($exit_status)";
                exit
            fi

            rsync -az --chmod=Dugo+rwx,Fugo+rw --remove-source-files
"$kdd"* kal@my.debian.server:/srv/datafiles/
            exit_status_2=$?

            if [ $exit_status_2 -eq 0 ]; then
                find "$kdd" -mindepth 1 -depth -type d -empty -delete;
                echo "[`date`]: success";
            else
                echo "[`date`]: failure ($exit_status)";
            fi
        else
            echo "[`date`]: no file to transfer.";
        fi
    else
        echo "[`date`]: keychain not initialized.";
    fi
else
    echo "[`date`]: keychain not initialized.";
fi

So after every reboot, the first thing I do is to open the cygwin bash
terminal so keychain gets eval'ed and I input the passwords for my
private keys.

The problem is that, sometimes, `ssh-add -l` would get stuck and not
return, even though the ssh-agent is clearly running. And so my cron
job gets stuck. If I open a new cygwin bash terminal, keychain is
eval'ed in ~/.profile and would also get stuck.

What am I doing wrong?

Best regards,
Kal

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]