Wednesday, June 21, 2017

Use crontab on AWS RedHat

1. Get your script defined and get it into a proper location on the machine:

touch script.sh
chmod +x script.sh

vi script.sh

Example of script copying files to a user home folders:

#!/bin/bash
cd /folder/test-pckg/
chown dest_user:dest_user filename*
mv filename* /home/dest_user/prod-pckg/


2. Add your script to crontab

crontab -e 
30 21 * * * /folder/test-pckg/script.sh

The above runs each day at 21:30 local machine time.

3. Verify if it runs under cron tab logs:
cat /var/log/cron

You should grep for a line like the below:
Jun 20 21:30:01 instance-name CROND[12092]: (root) CMD (/folder/script.sh)

No comments:

Post a Comment