[RT-AC3100][RT-AC66U B1] JFFS Script: "services-start" can not mount

elrengo

Regular Contributor
Hi! I'm proud owner of two Asus router, AC3100 & AC66U B1. AC3100 it is my principal router and AC66U B1 is configured as access point using wired connection with AC3100.

The AC66U B1 extend my Wi-Fi Coverage using diferent SSID. Also allows to me share media, mainly movies between TVs & mediaservers. I have some external drives with movies attached to a WD HD TV Live and both routers. AC3100 also has a rtorrent with share in my intranet downloaded movies. The performance to media is better with wired connection.

I have some configuration on "/jffs/scripts/services-start":

AC3100

Bash:
#!/bin/sh
#mount \\\\192.168.1.30\\My_Book /cifs1 -t cifs -o "username=elrengo" -o vers=2.0
mount \\\\192.168.1.30\\Seagate_Expansion_Drive /cifs2 -t cifs -o "username=elrengo" -o vers=2.0

cp /jffs/configs/.bashrc /tmp/home/root/.bashrc
chmod a+rx ~/.bashrc

AC66U B1

Bash:
#!/bin/sh
#mount \\\\192.168.1.30\\My_Book /cifs1 -t cifs -o "username=elrengo"
mount \\\\192.168.1.30\\Seagate_Expansion_Drive /cifs2 -t cifs -o "username=elrengo" -o vers=2.0
mount \\\\192.168.1.1\\Backup /cifs1 -t cifs -o "username=elrengo,password=xxxxxx" -o vers=2.0


cp /jffs/configs/.bashrc /tmp/home/root/.bashrc
chmod a+rx ~/.bashrc

When I restart both routers the mount command appear no be run. I have not mounted the filesystems. If when I can log to shh and run the script, it is working ok. I have access to mounts.
Someone can help me to found the way that mount points mounts when router restart o is starting.
Thanks in advance!
 

eibgrad

Part of the Furniture
Do you have JFFS scripts enabled in Administration > System?

BTW, you don't need to use backslashes, then escape it. You can just use forward slashes.

Code:
mount -t cifs //192.168.1.30/Seagate_Expansion_Drive /cifs2 -o 'vers=2.0,user=elrengo'

Also, you can't depend on '~' resolving to /tmp/home/root when the system calls your script since the script is NOT interactive.

Code:
chmod a+rx /tmp/home/root/.bashrc

Would also help if you wrote your scripts output to the syslog so you could see what's happening, good or bad.

Code:
#!/bin/sh
set -x # uncomment/comment to enable/disable debug mode
{
<your code goes here>
} 2>&1 | logger -t $(basename $0)[$$]

You can then search the syslog for the services-start event to see what happened.

Code:
grep services-start /tmp/syslog.log

Scripts like this sometimes fail because your assumptions about the availability of some resource turns out to be wrong. For example, it's a good idea to check that /cifs1 and /cifs2 actually exist. Perhaps setup a loop to keep checking before proceeding. Or perhaps the system just isn't ready to mount anything at the time you ask it. Again, it's a good idea to setup of a loop, or perhaps sleep for 60 seconds.

Code:
#!/bin/sh
set -x # uncomment/comment to enable/disable debug mode
(
MAX_TRY=5

until [[ -d /cifs1 && -d /cifs2 ]]; do sleep 10; done

tries=0

until mount -t cifs //192.168.1.1/Backup /cifs1 -o 'vers=2.0,user=elrengo,pass=xxxxxx'; do
    [ $((++tries)) -ge $MAX_TRY ] && break || sleep 10
done

tries=0

until mount -t cifs //192.168.1.30/Seagate_Expansion_Drive /cifs2 -o 'vers=2.0,user=elrengo'; do
    [ $((++tries)) -ge $MAX_TRY ] && break || sleep 10
done

cp /jffs/configs/.bashrc /tmp/home/root
chmod +x /tmp/home/root/.bashrc

) 2>&1 | logger -t $(basename $0)[$$] &

Notice I run the script in the background (&) to allow the router to continue moving forward.
 

elrengo

Regular Contributor
Hi! Sorry for my late answer.
Do you have JFFS scripts enabled in Administration > System?

Yes. I have a lot of scripts. working.

Also, you can't depend on '~' resolving to /tmp/home/root when the system calls your script since the script is NOT interactive.
Ok. Thanks for the observation! :)
Would also help if you wrote your scripts output to the syslog so you could see what's happening, good or bad.

Excellent!!! A new learning.

Notice I run the script in the background (&) to allow the router to continue moving forward.

How I can says that to the router? That script is auto run by Router when Start.

Thanks with all your comments. I'll put on working now!
 

elrengo

Regular Contributor
Code:
#!/bin/sh
set -x # uncomment/comment to enable/disable debug mode
{
<your code goes here>
} 2>&1 | logger -t $(basename $0)[$$]

Code:
#!/bin/sh
set -x # uncomment/comment to enable/disable debug mode
(
MAX_TRY=5

until [[ -d /cifs1 && -d /cifs2 ]]; do sleep 10; done

tries=0

until mount -t cifs //192.168.1.1/Backup /cifs1 -o 'vers=2.0,user=elrengo,pass=xxxxxx'; do
    [ $((++tries)) -ge $MAX_TRY ] && break || sleep 10
done

tries=0

until mount -t cifs //192.168.1.30/Seagate_Expansion_Drive /cifs2 -o 'vers=2.0,user=elrengo'; do
    [ $((++tries)) -ge $MAX_TRY ] && break || sleep 10
done

cp /jffs/configs/.bashrc /tmp/home/root
chmod +x /tmp/home/root/.bashrc

) 2>&1 | logger -t $(basename $0)[$$] &

Notice I run the script in the background (&) to allow the router to continue moving forward.
In firstone you use {} and in the script you use: () it's any difference?
 

eibgrad

Part of the Furniture
In firstone you use {} and in the script you use: () it's any difference?

Using ( ) explicitly creates a subprocess for the enclosed code, whereas { } does NOT. And whenever you run something in the background w/ &, it has to run as a subprocess.

All that said, if I had chosen to use { } in either situation, it would have worked. { } & would have implicitly been treated as a subprocess, just as if I had written ( ) &. But for clarity's sake, I prefer the latter syntax.
 

elrengo

Regular Contributor
Thanks!
 

elrengo

Regular Contributor
The script works! Fine! If I want to add a new resource only need to add:

tries=0

until mount -t cifs //192.168.1.1/Backup /cifs1 -o 'vers=2.0,user=elrengo,pass=xxxxxx'; do
[ $((++tries)) -ge $MAX_TRY ] && break || sleep 10
done

A question, why works the forward slashes. I understand that newwork use backward shlashes
Thanks
 

ColinTaylor

Part of the Furniture
A question, why works the forward slashes. I understand that newwork use backward shlashes
Backward slashes are a Windows thing. Linux typically uses forward slashes but the mount command will accept either.

The problem with using backward slashes in Linux is that it's the escape character. So you would need to double every single backward slash, e.g. "\\nuc" becomes "\\\\nuc", which is just unnecessary.
 

elrengo

Regular Contributor
Thanks!
 

Similar threads

Sign Up For SNBForums Daily Digest

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