简体   繁体   中英

Trouble with running a shell script via a Cronjob on an EC2 Instance

I am trying to to run a cronjob of a script on an EC2 Instance but it's simply not working The way I am running it right now is

15 * * * * root /home/ec2-user s3_upload.sh TestBucket

I wrote this when I did crontab -e

Right now I am in this directory /home/ec2-user/ so I don't know if maybe that has something to do with why it's not running.

I just don't understand this whole cron thing and how permissions work.

Any help is greatly appreciated!

  1. You can't specify a username in a user's crontab, only in /etc/crontab .

  2. You can't specify a directory in any form of crontab. To change directory, use cd.

  3. The environment is not the same. If you eg set PATH in .bashrc , these will not be automatically included, so it's safest to use full paths.

As root (assuming you want to run this as root and not ec2-user or something), run crontab -e and add

15 * * * * cd /home/ec2-user && /full/path/to/s3_upload.sh TestBucket

Make sure you can copy-paste the command in a root terminal and get it working, and read root's mail afterwards to see the command's output with possible error messages. If it still doesn't work, make sure you have these errors available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM