Wednesday, August 8, 2018

Set cronjob to run command on your server using SSH

SetCronJob is a web-based cronjob service, and currently, you can only set cronjob with URLs to your scripts.

If your cron scripts only support CLI (command line interface), then you may use our free service at Clustermin to create a cron trigger. It requires that you can access your server using SSH connections.

You can create a free account here. You can add up to 5 servers in the free account, and it'll be more than enough for your case.

First, you'll need to connect your server to Clustermin. For setting up cronjob, you should enter the user that has access to your web folders (public_html, www, etc.) and uncheck the box Create user. No worry, it will install nothing but a public SSH key into your authorized_keys file so that it can connect your server securely using SSH key next time.

Secondly, make sure your command works fine. Click the Execute button, then enter the whole cron command e.g.
php /home/your-user/example.com/proj/app/console do:something
and make sure it works as expected.

Thirdly, when you're sure the command works, visit Script > Add a script to create a script with the command as contents. Remember to check the box This is a private script.
Finally, visit Trigger > Add a trigger, then select your newly created at Run script, and your connected server at On servers.

When the trigger is created, you can copy the trigger URL, and set cronjob with it.

At your desired time, SetCronJob will execute (pull) the trigger, and Clustermin will execute the command on your server.

Let me know if it works for you ;-)

No comments:

Post a Comment