What's new

Custom script proper usage?

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

HuskyHerder

Senior Member
I started by appending my script to the wan-start below the ab-solution portion. The script is, just a sleep event to ensure the WAN is active, and then issue a pushover notification.

Is that the desired approach, to append to the existing script ?

Is there somewhere I could actually specify my individual script to be called ? So it could reside as itself in the scripts folder. I am unsure if appending to the wan-start script would cause issues in general or after updates from ab-solution. Mainly just making sure I don't muck anything up. ;)


My notification is working as desired.

Thanks for any pointers.
 
I started by appending my script to the wan-start below the ab-solution portion. The script is, just a sleep event to ensure the WAN is active, and then issue a pushover notification.

Is that the desired approach, to append to the existing script ?

Is there somewhere I could actually specify my individual script to be called ? So it could reside as itself in the scripts folder. I am unsure if appending to the wan-start script would cause issues in general or after updates from ab-solution. Mainly just making sure I don't muck anything up. ;)


My notification is working as desired.

Thanks for any pointers.
This should help you.
Code:
https://github.com/RMerl/asuswrt-merlin/wiki
I know it is a lot of reading but it will give you a good understanding of a lot of stuff going on in this forum.
 
You can create your own script and call it from lets say firewall-start in /jffs/scripts directory.
 
Thanks @skeal

Thats where I was, most of the afternoon and half the evening, reading, a little scratching my head too. :p

I also thought about the 2nd comment you made (calling from the other script) so yeah I was thinking along the correct lines. I’ll go that route I think.

Thanks again,
 
I was wondering if one of you more experienced scripting folks could look over my script. I am at a loss to explain why it fails. Maybe I have it placed in the wrong location to get called properly.


1. Pushover notification, script variation used for years on my Mac. Script to be used when I am working remotely and be notified of services start up after a reboot.
Code:
#!/bin/sh

touch /tmp/notifyme-log && echo "$(date) script start" >> /tmp/notifyme-log

while ! ping -c1 www.google.com &>/dev/null; do sleep 60; done

curl -s \
--form-string "token=***********" \
--form-string "user=************" \
--form-string "title=ASUS Router" \
--form-string "message=Starting up!" \
--form-string "sound=persistent" \
--form-string "priority=0" \
https://api.pushover.net/1/messages.json

echo "$(date) script complete" >> /tmp/notifyme-log
2. Works time and again on the Mac. As a saved script.
3. My script is placed in /jffs/scripts/ and chmod a+rx (per wiki)
4. My script is called from wan-start, single line call (Placed after ab-solution and before dnscrypt, or even after dnscrypt
Code:
sh notifyme
5. Working manually when calling the actual script on the router or even calling wan-start on the router.
Code:
From /jffs/scripts/
. notifyme = success
. wan-start = success
6. Script seems to time out on the router ? During a reboot and FAILS every time. Reboots from the GUI or through ssh are the same, and end in the same failure.

-- No log created

7. I am able to turn off Net access and run the script (on my Mac), then come back approximately 10 minutes later, re-enable net access and the script will succeed.
Code:
Sun Apr 15 11:59:39 EDT 2018 script start
Sun Apr 15 11:59:40 EDT 2018 script complete
Sun Apr 15 12:00:13 EDT 2018 script start
Sun Apr 15 12:00:13 EDT 2018 script complete
Sun Apr 15 12:00:15 EDT 2018 script start
Sun Apr 15 12:00:16 EDT 2018 script complete
Sun Apr 15 12:00:17 EDT 2018 script start
Sun Apr 15 12:00:17 EDT 2018 script complete
Sun Apr 15 12:01:54 EDT 2018 script start
Sun Apr 15 12:13:05 EDT 2018 script complete
8. I am using TextWrangler to create the script and saved as unix file type on my Mac. Script is created using nano on the router and saved.
9. Even though the script succeeds when ran manually, I have tried the dos2unix command on the script with no noticeable effect.
9. Running scripts/processes on RT-AC5300, are in my signature


Lastly I have not been able to get the "logger" command to work any guidance on how to use it. When I attempt to use it, the script just hangs. So I know this is very likely user error. :(


Thanks for any thoughts or hints that you can provide me.

HH
 
4. My script is called from wan-start, single line call (Placed after ab-solution and before dnscrypt, or even after dnscrypt
Code:
sh notifyme
You must specify the full path to your script. /jffs/scripts is not part of the default search path.
 
@ColinTaylor

Thanks, though now I feel kinda silly as I didn't notice the call path in the dnscrypt line. DOH well live and learn.

Working like a charm now.
 
Will merlins f/w do a job consisting of "@reboot sleep 60 && my_script.sh"? I gave it a few go's tonight but it was no luck from what I could tell. Ill try to pipe it into a log file tomorrow. But you all may be able to save me a bit of work.
I cant tell yet if its my error or it will not run with the @reboot portion. I can call and run my_script fine from something like firewall-start. So its not the script and I already have a script to re add the job at each boot so thats not the issue either.


Thanks

HH,
 
Will merlins f/w do a job consisting of "@reboot sleep 60 && my_script.sh"? I can call and run my_script fine from something like firewall-start. So its not the script and I already have a script to re add the job at each boot so thats not the issue

If you want to run a script just once after/during the reboot, then call your script either from init-start or services-start.
 
Thanks for the thoughts. I’ve been using firewall-start so Skynet AB solution etc are all up. Running my script as a separate process so as not to slow down other things on the router.

It’s working great. It’s acutally running twice but only rarely. Sleeping for circa 4 min to allow services to start and settle down to normal. Then checking a ping to ensure connectivity. Finally sends a push notification with wan ip to my phone.

Mainly script was to be used if traveling to let me know VPNs up etc. WAN was a bonus I added at the last minute.

Just means I need to teach myself a little more and put a few more checks into my script.

Oh well more learning. That’s a good thing. You all have already. Helped me learn more than I thought I would. It’s not really as hard as I always led myself to believe. But again I’m no where near your level. I’m still learning to crawl about.

That rare double run irritates me, yeah touch of ocd here. But again I’ve been having some fun learning the last few weeks. Especially after recovering from a few blunders.

I’m using the dnsomatic scripts for several services and the asus ddns as well but just had to send the push with WAN to myself because I could :p


Thanks again
 
Last edited:
It’s acutally running twice but only rarely.

That rare double run irritates me...:p

I use this technique in firewall-start etc. (obviously with a with a different FD value per script!)
Code:
logger -st "($(basename $0))" $$ "Martineau Firewall customisation Starting.... " $0${*:+ $*}

# With DUAL-WAN and TrendMicro ?, this event gets triggered twice!!!
# Prevent script from running twice @boot
LOCKFILE="/tmp/$(basename $0)-flock"
FD=201
eval exec "$FD>$LOCKFILE"
flock -n $FD || { logger -st "($(basename $0))" $$ "Martineau Firewall customisation ALREADY running...ABORTing"; exit; }

<snip>           # Actual firewall-script code goes here

# Spoof a long running script!
sleep 5
# Delete the locking semaphore file
flock -u $FD

logger -st "($(basename $0))" $$ Martineau Firewall customisation complete.
 

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