Cron to an API

I need a Cron that runs everyday that calls an API, following the documentation I made it like this:

@daily https://example.com/api

  • Is the use of the shortcut done properly or should I just use 0 0 * * *
  • And more importantly is the api call done correctly? Or do I need a special parameter, or run a sh that does the call itself?

I'm not sure if CRON of OpenWRT recognizes keywords like @daily anyway you can try if it does work.. but just calling a URL won't work since OpenWRT (or linux) won't understand it since it is not a command, you can use curl or wget before the url of the API.

2 Likes

Ok, do note that by default OpenWRT doesn't come with curl, so I had to install it. Tried the command by ssh and it seems to work fine.

While wget does come by default, it downloads the page and I think that works, but for the sake of logging and not creating useless files, it's better to use curl.

Just to be sure I changed the cron to 0 0 * * *. So this should work fine now. Just for curiosity I would like to know how the shortcuts (@yearly @daily, etc) work.

Use the -O switch for wget to redirect the output elsewhere, e.g. /dev/null:

wget -O /dev/null http://example.org/api

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.