#!/bin/sh

unset SSH_AGENT_PID
        
if test -f "${HOME}/.ssh-cron-agent"; then
        source "${HOME}/.ssh-cron-agent"
fi

case $1 in
help)
        cat <<EOF
use ssh-agent from crontab

 INSTALL
  1. install this script somewhere executable in your PATH (/usr/local/bin)
  2. add a '@reboot ssh-cron-agent start' to your crontab (crontab -e)

 USAGE
  - when booted you need to feed and unlock the keys once with 'ssh-cron-agent add [KEYS]'
  - add a 'source ssh-cron-agent' line to every script which will be run from cron and needs ssh

  you can list all added keys with 'ssh-cron-agent list' and
  delete them with 'ssh-cron-agent del'.
  'ssh-cron-agent stop' quits the agent (until cron restarts)
  'ssh-cron-agent shell ..' enters a shell which uses the ssh-cron-agent
  'ssh-cron-agent exec command ..' execs command with ssh-cron-agent
  'ssh-cron-agent test host' tests if it is possible to connect and execute something on host
EOF
        ;;
start)
        eval ssh-agent -k >&/dev/null
        ssh-agent -s | grep -v echo >"${HOME}/.ssh-cron-agent"
        ;;
stop)
        eval ssh-agent -k
        ;;
add)
        shift
        ssh-add "$@"
        ;;
off)
        ssh-add -D
        ;;
list)
        ssh-add -l
        ;;
test)
        if test "$(ssh -o BatchMode=yes $2 echo test)" = "test"; then
                echo "success"
                exit 0
        else
                echo "failure"
                exit 20
        fi
        ;;
shell)
        shift
        exec $SHELL "$@"
        ;;      
exec)
        shift
        exec "$@"
        ;;      
esac
ssh-cron-agent

ssh-cron-agent (last edited 2008-09-14 20:01:52 by ct)