Crontab in AWS CloudFormation Userdata

后端 未结 3 947
春和景丽
春和景丽 2021-02-10 13:21

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\") |          


        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-10 13:29

    I had similar issue like others are saying here that these commands work fine from CLI but when added through userdata not working. After several hours of head scratching search finally realized I had to add line "#!/bin/bash" before crontab setup commands. This fixed my problem, some very well experienced people might know this already but if you are bit new to this realm may not know this. My script look like below.

    !/bin/bash sudo su echo '*/1 * * * * command1 command2' > /tmp/mycrontab.txt sudo -u ubuntu bash -c 'crontab /tmp/mycrontab.txt'

提交回复
热议问题