What's new

how to run cron and other scripts on startup?

  • 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!

steve288

Occasional Visitor
I'm new to this site and hope that I have the right NewsGroup that I'm posting on.

I have a new router. ASUS RT-AC66U B1

The software seems to be ASUSWRT.

I have written a little script that checks my outside IP and emails me if it has changed. It works fine when I run the command from command prompt.

I'm struggling with getting it to be persistent after a boot. My understanding is that after a reboot the tmp folders are cleaned out because they are virtual.
I have read considerably and it seems to say that I need to create a file called init-start in the jffs / scripts folder and make it executable.

I have seen some comments say that / jffs scripts needs to be enabled, and then others that seem to say that on new routers its already enabled. Perhaps I'm confused and dazed.
Can anyone provide and advice on getting this to work? I thought that this would work without me having to change the firmware, this software which appears to be asuswrt ??

Regards
 
Last edited:
Thank you for your help.

Sorry, I tried to figure out what asuswrt and merlin was and really thought that asuswrt-merlin where really two names for the same thing. I did see that it was somehow derived from tomato. I have installed and used tomato and ddwrt on several routers in the past.
I was hoping to keep it stock. DDWRT is not the easiest to install. And the web site is a labyrinth of links and peacock threads. Although I have done it several times.
I have read the thread you provided on using stock software but it looks like ?? this method does not work anymore. At least for some. The last post of dec 2020 seems to indicate that ??
Can anyone confirm this? I did try what is written there but it did not work.

I sort of just wanted to leave things alone as far as firmware. I'm kind of tired of spending a lot of time on upgrades etc. If ASUS does this for me I m happy with that.

However, if I did use Merlin will i need to set up my router again and will vpn be deleted so I will have to set that up again?
 
Thank you for your help.

Sorry, I tried to figure out what asuswrt and merlin was and really thought that asuswrt-merlin where really two names for the same thing. I did see that it was somehow derived from tomato. I have installed and used tomato and ddwrt on several routers in the past.
I was hoping to keep it stock. DDWRT is not the easiest to install. And the web site is a labyrinth of links and peacock threads. Although I have done it several times.
I have read the thread you provided on using stock software but it looks like ?? this method does not work anymore. At least for some. The last post of dec 2020 seems to indicate that ??
Can anyone confirm this? I did try what is written there but it did not work.

I sort of just wanted to leave things alone as far as firmware. I'm kind of tired of spending a lot of time on upgrades etc. If ASUS does this for me I m happy with that.

However, if I did use Merlin will i need to set up my router again and will vpn be deleted so I will have to set that up again?
Yes, running scripts on stock Asus still works. Will dig for the process and get back to you later today.
 
Yes, running scripts on stock Asus still works. Will dig for the process and get back to you later today.
@steve288 Try a basic test of this with stock firmware. SSH into the router and enter
Code:
nvram set script_usbmount="touch /jffs/success"
nvram commit
service reboot
As stated before you need to have a USB drive plugged into the router.

Once the router has rebooted SSH back into the router and see if that file has been created.
Code:
ls -l /jffs/success
 
See this: https://www.snbforums.com/threads/add-swap-to-usb-drive-on-asus-router.46911/ You will need to have a USB drive inserted. The swap file is not necessary but is recommended.
I'm sorry that the problems seem to go on and on.

I have read the thread. Here is what I have done.

Inserted 16 MB USB drive into router, formatted fat. given name of MYFLASH. (Ok its what I have available)

Run:

df

Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 40064 40064 0 100% /
/dev/root 40064 40064 0 100% /
devtmpfs 127752 0 127752 0% /dev
tmpfs 127856 3120 124736 2% /tmp
/dev/mtdblock4 64256 5564 58692 9% /jffs
/dev/sda 15916 0 15916 0% /tmp/mnt/MYFLASH

Run:

dd if=/dev/zero of=/tmp/mnt/ MYFLASH /myswap.swp bs=1k
But this just gives me the dd command help file, meaning something is wrong.
Im not sure what to put for count= but I thought that if I didn't put it it would just use the whole usb key.

You say I don't necessarily need the swap command. If I wanted to start without the swap file, what would I do?

The commands swapon, mkswap, nvram are all new to me.

I suppose its at time like this where the OP feels obligated to make the ubiquitous statements like, I've managed various Windows servers, and Linux computers/appliances and written many scripts and generally poked my way along so I'm not completely new to this but will admit my ignorance in these particular areas, well and many other, as I sit at home twiddling my fingers.

Regards
 
dd if=/dev/zero of=/tmp/mnt/ MYFLASH /myswap.swp bs=1k
But this just gives me the dd command help file, meaning something is wrong.
There are typo's (extra spaces) in that command, and elsewhere in the original post. I suspect some text got mangled in the move to the new forum. And you should use the count parameter. The correct command is:

Code:
dd if=/dev/zero of=/tmp/mnt/MYFLASH/myswap.swp bs=1k count=262144
 
dd if=/dev/zero of=/tmp/mnt/MYFLASH/myswap.swp bs=1k count=262144
Your right.

I did look up the command for syntax and could not find it described in the old link, but still followed it slavishly. Your new command works, thanks.. sort of. Now I'm getting another error.

dd if=/dev/zero of=/tmp/mnt/MYFLASH/myswap.swp bs=1k count=262144
dd: writing '/tmp/mnt/MYFLASH/myswap.swp': No space left on device
15917+0 records in
15916+0 records out

You mention that I "should use the count parameter " but should this number change based on the size of my USB drive ?? Or am I confused with the dd command.
Also where do I put the commands that I want to run on boot-up. I dont really see that in the link that you provided.
Regards
 
Your right.

I did look up the command for syntax and could not find it described in the old link, but still followed it slavishly. Your new command works, thanks.. sort of. Now I'm getting another error.

dd if=/dev/zero of=/tmp/mnt/MYFLASH/myswap.swp bs=1k count=262144
dd: writing '/tmp/mnt/MYFLASH/myswap.swp': No space left on device
15917+0 records in
15916+0 records out

You mention that I "should use the count parameter " but should this number change based on the size of my USB drive ?? Or am I confused with the dd command.
Also where do I put the commands that I want to run on boot-up. I dont really see that in the link that you provided.
Regards
The reason you should use the count parameter is so that you can set a sensible size for the swap file (in this case 256MB) and so that it doesn't just crash out with the error you've just got leaving absolutely no space on the disk for housekeeping functions.

However, I mis-read your previous post and thought you were using a 16GB flash drive. Now that I look again I can see it is in fact 16MB! I didn't think such small devices were ever made. So that explains the error.

Stepping back a bit. You don't actually need a swap file. Your original request was to automatically run a script on boot. You now know how to do that.
 
Ahh the memories.
All of my large USB keys are being used for stuff right now. And I can't go to the store because they are all closed, everything is online or door service. Indeed these 16mb or 8 mb or other mb sizes where made and were a godsend. You may recall back in the day, we only had 720kb floppies, then 1.2 mb floppies, then the huge 1.44 mb floppies came out. We thought we had died and gone to heaven. MS Word came on about 20 Floppies. Unix/Xenix was some ridiculous number. So much so that you could get it on tape instead.

But when you could get 8mb and 16MB usb OMG, this was the future. Star Trek was real !! This USB i dug out, I'm using actually looks like it was from a trade show, and has "Gateway" on it. Remember Gateway computers, you know the Cow logo. mmm what ever happened to them.

You have stated that I already know how to run it automatically, well my ignorance tells me I really don't. I assume it has something todo with the command. Maybe ??

nvram set script_usbmount="touch /jffs/success"
nvram commit
service reboot

Should I put and executable filename where the "touch /jffs/success"
is.
Regards
 
You have stated that I already know how to run it automatically, well my ignorance tells me I really don't. I assume it has something todo with the command. Maybe ??

nvram set script_usbmount="touch /jffs/success"
nvram commit
service reboot

Should I put and executable filename where the "touch /jffs/success"
is.
Regards
Yes. So you need to put your script in the /jffs directory and make sure it has executable permissions. Then put the script name including the path in that nvram variable. e.g. nvram set script_usbmount="/jffs/myscript.sh"
 
Yes. So you need to put your script in the /jffs directory and make sure it has executable permissions. Then put the script name including the path in that nvram variable. e.g. nvram set script_usbmount="/jffs/myscript.sh"
Sorry got sidetracked by other things.
I will give this a try and get back if I have any interesting results.
Thanks.
 
I have successfully got my script up and running.
Big thanks you ColinTaylor, who appears to be part of the furniture, who was patient with my ASUS novice-ness who helped me keeping the script running after a boot of the router. I should state that this runs on the ASUS factory installed default software .

Basically the script checks the current IP address against any changes and then emails out an email if it has changed.
It means that I don't have to have my computer on running some sort of DNS updater, or at least gives me a belt and suspenders approach. There are other ways of doing this but this is one. I may investigate others.

I don't know if this is of any importance to any one I can post it if you want?
During these times just trying to keep my brain up a little.
Thanks again all.
 
It means that I don't have to have my computer on running some sort of DNS updater, or at least gives me a belt and suspenders approach. There are other ways of doing this but this is one. I may investigate others.
The router has the ability to automatically update certain DDNS services which might be of use to you. WAN > DDNS
 
I did try to set this up but could not do it. I have forgotten all of the details but the message on the router says.

The wireless router currently uses a private WAN IP address.
This router may be in the multiple-NAT environment and DDNS service cannot work in this environment.

I even reached out to some news groups, cant remember where now and they agreed that my asus router could not do this.

Thus I started on this little adventure. I believe this is called double NAT-ing.

Frankly I thought it odd at the time. Because for millions of people they have an ISP's router downstream.

Was I wrong?
Regards
 
Yes, if you're in a double-NAT setup the router's DDNS function will not work and you will have to use your script.

Merlin's third-party firmware has the ability to update DDNS even with double-NAT.
 
Yes seems odd that it would not be included in Asus firmware. DDWRT can do it also. I guess I wanted to walk before running. With the difficulty I had, it seems like running before walking at this point.
Thanks.
 
Hello guys,

need help here, once works before, but after power off, no longer do the job, please see below

Filesystem 1K-blocks Used Available Use% Mounted on
ubi:rootfs_ubifs 79592 69856 9736 88% /
devtmpfs 466784 0 466784 0% /dev
tmpfs 466900 244 466656 0% /var
tmpfs 466900 5960 460940 1% /tmp/mnt
ubi1:data 4584 68 4244 2% /data
tmpfs 466900 5960 460940 1% /tmp/mnt
tmpfs 466900 5960 460940 1% /tmp
/dev/mtdblock9 48128 7240 40888 15% /jffs
/dev/sda 511384 263192 248192 51% /tmp/mnt/MYFLASH

not sure why there are many tmpfs ? is this the problem.

Many thanks
 
Similar threads
Thread starter Title Forum Replies Date
P ASUS RT-AX56U run script after reboot ASUS AC Routers & Adapters (Wi-Fi 5) 1

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