Crontab in AWS CloudFormation Userdata

谁说我不能喝 提交于 2020-01-01 03:38:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!