The goal is to get a bash script that connects to EC2 to download offsite backups. I have this, but I have to keep running them from the terminal manually as they fail from the crontab with the error "Permission denied (publickey)", so the key is obviously failing to add.
There's obviously a hole in my understanding. I've been tinkering for a couple of hours trawling Google and still haven't got it working. What am I doing wrong in terms of getting the script to add the keys itself?
#!/bin/sh
# Add the client key so we can SSH in
eval "$(ssh-agent)"
ssh-add ec2-key.pem
# Download the web file backup.
# Example file web1_2013-06-30_00-30.tar.gz
WEBDATE=`date +"%Y-%m-%d"`;
echo $(date) " - Web Backup >> Running secure copy: scp {user}@{ip}:/var/backup/web1/web1_$WEBDATE* site-files/"
scp {user}@{ip}:/var/backup/web1/web1_$WEBDATE* site-files/
... etc ...