问题
How to set crontab when using AWS CloudFormation Userdata?
I am setting
(crontab -l ; echo "0 * * * * wget -O - -q http://www.example.com/cron.php") | crontab -
But the cron is not setting. Is there a specific format which I should be using?
回答1:
This will work, set this in your template, for your instance:
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"#!/bin/bash\n",
"echo '0 * * * * wget -O - -q http://www.example.com/cron.php' > /tmp/mycrontab.txt\n",
"sudo -u ubuntu bash -c 'crontab /tmp/mycrontab.txt'\n",
]
]
}
}
回答2:
To do this properly you should do the following inside the bash script:
crontab -l > /tmp/mycrontab
echo '0 * * * * wget -O - -q http://www.example.com/cron.php' >> /tmp/mycrontab
crontab /tmp/mycrontab
来源:https://stackoverflow.com/questions/39102613/crontab-in-aws-cloudformation-userdata