0

This question already has an answer here:

I've written a shell script that does the following:

  • Retrieve mail from a POP3 account (using GetMail)
  • Save a copy of that email to S3 (using AWS CLI)
  • Email me the filesize of the email

The script runs fine manually, and technically runs from CRON, but it only seems to be sending the email. The getmail and S3 bits don't seem to run.

Everything I've read seems to hammer home the message that I need to be careful about relative paths and the like when using CRON, but I think I'm using absolute paths everywhere I need to be, so I'm stumped as to what the issue could be.

My Shell Script is here:

#!/bin/bash

# Run GetMail
getmail -r /PATH/TO/EMAIL/getmail.email

# Save to S3
aws s3 cp /PATH/TO/SCRIPT/email-backup.mbox s3://XXXXXXXXXX/email-backup.mbox 

# Send Confirmation Email

SUBJECT="EMAIL SUBJECT"
EMAIL="My@EMAIL.COM"

# Get current filesize
FILENAME=/PATH/TO/SCRIPT/email-backup.mbox
FILESIZE=$(stat -c%s "$FILENAME")

# Email Content
EMAILMESSAGE="/tmp/emailmessage.txt"
echo "EMAIL BODY" >$EMAILMESSAGE
echo "" >>$EMAILMESSAGE
echo "Current File Size: $FILESIZE bytes" >>$EMAILMESSAGE

# Send the Mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE

marked as duplicate by Dennis Williamson, mdpc, Jenny D, Ladadadada, DKNUCKLES Jun 4 '14 at 13:16

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

I've had a similar problem, because CRON can be quite finicky. My best guess would be that you need to add the path to the aws command, for instance:

/usr/local/bin/aws s3 cp /PATH/TO/SCRIPT/email-backup.mbox s3://XXXXXXXXXX/email-backup.mbox 

Good Luck!

  • This did it, thanks! I was so preoccupied with paths to scripts I hadn't even considered paths to commands. Really appreciate the help! – binaryorganic Jun 3 '14 at 19:57
  • Excellent. Not a problem. – paranoid Jun 3 '14 at 21:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.