Crontab in AWS CloudFormation Userdata

倖福魔咒の 提交于 2019-12-03 08:46:57

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",
            ]
        ]
    }
}

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