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?
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",
            ]
        ]
    }
}
and in YAML
UserData: 
    Fn::Base64:
      Fn::Join:
        - ""
        - - "#!/bin/bash\n"
          - "echo '0 * * * * wget -O - -q http://www.example.com/cron.php' > /tmp/mycrontab.txt"
          - "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
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With