Need help setting up a cron job

EeK

Regular Contributor
Hey, all.

I have an RT-AC86U with Asuswrt-Merlin 386.2_4 installed (yeah, I need to update it) and would like to ask for some help setting up a cron job for the SmartDNS service that I use.

Since my ISP uses dynamic IP, it changes every so often, requiring a manual update from my part, so that the SmartDNS server has my current IP address. I looked into automating that task and found this info in the SmartDNS provider's website:

Cron Job (Routers, Linux)

Using a cron job to call curl, you can query our API periodically to update your IP address. Check out our IP Address API article for more information. An example cron job entry would look something like this (this updates your IP address every 5 minutes):

*/5 * * * * curl -u PUT_YOUR_API_KEY_HERE:x -X PUT https://www.getflix.com.au/api/v1/addresses.json

You need to get your API key from the 'Advanced' section under your Getflix account. Substitute the PUT_YOUR_API_KEY_HERE text with your API key.

Now, even after reading the Asuswrt-Merlin Wiki (more specifically, these two entries), I have no idea how to do that. I already have a few scripts installed (amtm, Diversion, Skynet) and can SSH into the router using Putty - that's as far as my programming skills and knowledge go.

I'd really appreciate it if someone could guide me step-by-step on how to set up the specific cron job mentioned above (I already have the API key, don't worry).
 

ColinTaylor

Part of the Furniture
You need to add a command to the services-start script. As you already have some scripts installed it's likely that a version of this script already exists on your router.

Edit that file by entering:
Code:
nano /jffs/scripts/services-start

Scroll to the bottom of the file and add this line:
Rich (BB code):
cru a getflix "*/5 * * * * curl -u <api_key>:x -X PUT https://www.getflix.com.au/api/v1/addresses.json"
Obviously you need to replace <api_key> with the appropriate key.

Now save the file (Ctrl-O) and then exit (Ctrl-X)

Reboot the router.
 

FernandoF

Occasional Visitor
You need to add a command to the services-start script.
Alternatively to setting a cron job, would it work to add the required update command to a wan-event "connected" script instead? My understanding is when the ISP changes the WAN IP address, a "connected" event is triggered. At least that's what I see once a week with my WAN connection.

If both options are feasible, is there a preferred solution?

I apologize in advance if the above suggestion doesn't make sense. I'm not an expert and see this as a learning opportunity for me. Thank you.
 
  • Like
Reactions: EeK

ColinTaylor

Part of the Furniture
I think any of the suggestions above would work. I did consider the DDNS option but as the OP implied his Linux command lines skills were limited I thought adding a single line to an existing file was the simplest solution.
 

EeK

Regular Contributor
I think any of the suggestions above would work. I did consider the DDNS option but as the OP implied his Linux command lines skills were limited I thought adding a single line to an existing file was the simplest solution.

You're right, and even that was already too complicated for me, haha.

If I SSH into the router using Putty and enter the first command, it brings me to a screen with the following info:

Code:
GNU nano 5.5              /jffs/scripts/services-start              Modified
#!/bin/sh
|
/jffs/scripts/scmerlin startup & # scMerlin

| is the command line where I can actually type. That's the bottom of the screen. If I scroll up, a bunch of lines with /tmp/home/root# nano /jffs/scripts/services-start appear, with the very last one also having /jffs/scripts/services-start next to it.

Not sure what to do from here. :oops:
 

ColinTaylor

Part of the Furniture
nano is a full screen editor, a bit like Windows Notepad. You should have a screen like this:
Untitled.png
Use the arrow keys to move the cursor to the bottom line and enter your command. Then press Ctrl-O to save (Write Out) the file.
Untitled2.png
Press Ctrl-X to exit the editor.

EDIT: Fixed typo. It should have said Ctrl-O to save the file
 
Last edited:

EeK

Regular Contributor
nano is a full screen editor, a bit like Windows Notepad. You should have a screen like this:
View attachment 40803
Use the arrow keys to move the cursor to the bottom line and enter your command. Then press Ctrl-X to save (Write Out) the file.
View attachment 40804
Press Ctrl-X to exit the editor.

Thank you very much for the detailed instructions! I was finally able to set it up, thanks to you.

Now, it's just a matter of waiting for an IP refresh and making sure it works. :D
 

ColinTaylor

Part of the Furniture
@EeK After you've rebooted your router you can verify whether you edited the file correctly by entering this command:
Code:
cru l
You should see that one of the lines looks like this:
Rich (BB code):
*/5 * * * * curl -u XXXXXXX:x -X PUT https://www.getflix.com.au/api/v1/addresses.json
 

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top