I want to use s3cmd to preserve the logfiles on an Amazon Linux instance when the instance terminates (mainly as part of an auto-scaling group, when the group scales down). I have a script that runs fine from the command line. It also executes on reboot/shutdown (it logs its message in the /var/log/messages file), but the critical part, the s3cmd command, isn't executing when the script is run as part of the shutdown or reboot process. Is there some reason why s3cmd wouldn't run when executed as part of the shutdown process? The script containing the s3 command is linked to K000sendlogtos3 in the rc0.d and rc6.d directories, so it should get executed before any of the services are stopped. Any ideas?
I figured it out (with some help). It was a pathing problem -- not only for the s3cmd tool, but also for the ec2-metadata tool. And I needed to explicitly state the location of the s3cmd config file. Here is the working script, in case anyone is interested:
s3cmd --config /root/.s3cfg put -r $LOG_FILE_LOCATION $s3_dest >> /var/log/messages 2>&1
echo "date" - sendlogtos3 executed >> /var/log/messages
rm -f /var/lock/subsys/0sendlogtos3
case "$1" in