What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Run command during router startup

tglesel

Occasional Visitor
I need to run a simple command during startup of my RT-AX92U = "rm -rf /tmp/mnt/mydisk/.smartsync" to ensure smartsync of my usb device is working after reboot
I am absolutely not a Linux and shell script expert, but I am familiar with some basic Linux commands, and I have setup telnet access to my router. I have been searching some threads on this forum, and I can see that I need to use "nvram" command, but the threads get a bit too complex for me as they are referring to shellscripts and cronjobs. Would it be possible just to give a "nvram" command followup by the "rm" command above and if yes what would the correct syntax be, to be sure the directory is deleted each time my router startup?
 
I think you need to edit your services-start file with winscp or similar and then add a cron job, using the command merlin has called "cru" which makes it easier.
However a "cronjob" is a command that runs to a time schedule. As your command just a run once, a cronjob might not be the way to do it, you might be able to just enter the code below without the cru bit (I'm not 100% on services-start, i'm a novice)

The reason you pu itt in services-start or it will disappear on a reboot.

It would be something like cru a MyScript 0 01 * * * rm -rf /tmp/mnt/[I]mydisk[/I]/.smartsync" as a cron to run at 1am everyday.
Note that the switch 0 01 the first 0 simply means zero minutes past the hour, and the 01 means 1AM, that said you only need it as a run once so this may not apply. "MyScript" is just to name your script and can be anything.

or in your case i think its just your command without the "cru a MyScript 0 01 * * *" bit to run it just once on start up. (not sure needs checking by the smart guys)


I learnt this from experiments with rsync.

I am no expert, and this may not be fully correct so don't do anything yet until others have checked.

I am invoking others to check please @ColinTaylor @SomeWhereOverTheRainBow @RMerlin

Also note, I think there is already a Disk Check Script, that might serve your purposes on AMTM https://github.com/RMerl/asuswrt-me...-Check-at-Boot-or-Hot-Plug-(improved-version)

Either way, good luck !
 
Last edited:
I am using stock Asus firmware on my 92U, so I do not think I can use "cru"
Ahh, then the amtm script is moot, perhaps just adding the line on services-start might be the way.
 
Ahh, then the amtm script is moot, perhaps just adding the line on services-start might be the way.
Sounds like a good suggestion. My Linux knowledge is however a bit fragmented. Would you be able to give me a hint on where I find service-start and how I add the command to the file
services-start and the other user scripts are Merlin-only added features.
Would it be possible with "nvram" command? As far as I can see it is supported in stock Asus firmware, but not sure how to use it in connection with the "rm" command above. My Linux knowledge is a bit fragmented...
 
I don't use stock firmware so I don't know what functions are available in it.

Try searching for posts that talk about the NVRAM variable script_usbmount. So something like:
Code:
nvram set script_usbmount="rm -f /tmp/mnt/mydisk/.smartsync"
You'd only use the -r parameter if .smartsync was a directory rather than a file.
 
I don't use stock firmware so I don't know what functions are available in it.

Try searching for posts that talk about the NVRAM variable script_usbmount. So something like:
Code:
nvram set script_usbmount="rm -f /tmp/mnt/mydisk/.smartsync"
You'd only use the -r parameter if .smartsync was a directory rather than a file.
Thanks, I will try to look into that variable, and see if I can get it to work. .smartsync is a directory so I need the -r
 
My Linux knowledge is however a bit fragmented. Would you be able to give me a hint on where I find service-start and how I add the command to the file
If you use winSCP (https://winscp.net) you can log in to your router and use the search function to find it but as Colin just pointed out it is Merlin specific so you won't find it on stock.

services-start is in the jffs/scripts folder then you just use the edit tool in winscp to edit it.

You might be better off with Merlin f/w it is great for things like this.
 

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

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