Home>

〇 There is a process that I want to run to get up.
I searched for a way to configure cron on EC2 and tried using crontab, but it doesn't work. ..

I'm at a loss because I don't know if the description of crontab is wrong or if crontab itself is wrong.
I am glad if you could tell me.

[When executing the process of /home/ec2-user/html/cron/test.php every minute]

▼ I did the following.
① At the SSH terminal$sudo vi/etc/crontabHit.
② In crontab* /1 * * * /usr/bin/php /home/ec2-user/html/cron/test.phpAdd and save

But the process is not executed ...

I would appreciate it if you could teach me.

  • Answer # 1

    / etc/crontabIs run with root privileges and is usually used when you want to run system jobs on a regular basis.
    There is no reason to use it this time for the purpose.
    Edit the crontab of the user who wants to execute the file and set it there.
    However, it should still be executed (since it has root privileges, there is no lack of privileges), but it is not executed because the cron notation format is incorrect.
    */1 * * *
    If you want to run every hour* */1 * * *Is the correct way to write.

    And personallyWe do not recommend using the crontab command to edit cron settings..
    But why,crontab -eSo you can certainly edit the current user's cron settings,
    At that timecrontab -rIf you hit the wrongThe cron settings disappear..
    There is no particular confirmation, and the setting will be empty in one shot..
    This is very risky as e and r are next to each other on QWERTY keyboards.
    So, explicitly using vim etc./ var/spool/cronI recommend the method of editing the cron settings of the corresponding user under it.
    If you want to edit the cron configuration file of ec2-user, you can do as follows, for example.

    sudo vim/var/spool/cron/ec2-user

  • Answer # 2

    ① Type $sudo vi/etc/crontab in the SSH terminal

    The file to be set is incorrect.
    Set cron with the privileges of the user you want to run.
    If you set with ec2-usercrontab -eLet's edit and set with.
    * There is no need to directly tamper with/var/spool.

    ② Add */1 * * * /usr/bin/php /home/ec2-user/html/cron/test.php to crontab and save

    There is a mistake in specifying the execution time. Unlike the first one, this one is easier to search and find, so please check it again.

  • Answer # 3

    Try to access it on an http basis with a crawler such as wget or curl