Skip to content

Instantly share code, notes, and snippets.

@stanlee321
Last active August 12, 2020 15:51
Show Gist options
  • Save stanlee321/eb3553829142756ebaad4c68136c43b5 to your computer and use it in GitHub Desktop.
Save stanlee321/eb3553829142756ebaad4c68136c43b5 to your computer and use it in GitHub Desktop.
USER SSH ADD TO EC2 and config crontab
$ ssh-keygen -t rsa
$ cat /you/.ssh/id_rsa.pub | ssh -i pem_file.pem [email protected] "cat >> .ssh/authorized_keys"
}
# CRONTAB
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of week (0 - 6) (Sunday to Saturday;
# │ │ │ │ │ 7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * * command_to_execute
###### Sample crontab ######
# Empty temp folder every Friday at 5pm
0 5 * * 5 rm -rf /tmp/*
# Backup images to Google Drive every night at midnight
0 0 * * * rsync -a ~/Pictures/ ~/Google\ Drive/Pictures/
Check that cron is running
If cron isn't running then your commands won't be scheduled ...
ps -ef | grep cron | grep -v grep
should get you something like
root 1224 1 0 Nov16 ? 00:00:03 cron
or
root 2018 1 0 Nov14 ? 00:00:06 crond
If not restart it
/sbin/service cron start
or
/sbin/service crond start
sudo /etc/init.d/cron start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment