Unfortunately no one can be told what fun_plug is - you have to see it for yourself.
You are not logged in.
Hi,
I have created a script, despite being a Linux newbie, that will mount my drives attached to the DNS323 via the USB.
When the NA starts up, I do not get the drives mounted. If I telnet in and run the script it works fine.
I get
insmod: cannot insert '/mnt/HD_a2/EPS/usb-storage.ko': File exists mount: can't find /mnt/usb80 in /etc/fstab
which I'd expect as the file loaded in the restart of the NAS and I've removed the 80GB drive for now.
fun_plug is listed as
/mnt/HD_a2 # ls -l fun*
-rwxrwxrwx 1 nobody 501 2180 Mar 6 2010 fun_plug
The directory is
drwxrwxrwx 2 nobody 501 4096 Nov 16 2010 EPS
and the script is
-rwxrwxrwx 1 nobody 501 1488 Apr 2 2010 eps.sh
In funplug I have
# EPS directory path EPS_SCRIPT=/mnt/HD_a2/EPS/eps.sh echo $EPS_SCRIPT
where the other parameters are defined and
# # Run any sepcific EPS stuff # if [ -x $EPS_SCRIPT ] ; then echo "*** Running $EPS_SCRIPT ... ***" . $EPS_SCRIPT fi # Start Twonky Media Server if it exists if [ -x $TWONKY_SCRIPT ]; then echo "* Running $TWONKY_SCRIPT ..." . $TWONKY_SCRIPT fi
at the bottom of the script
The script is as follows
#!/bin/sh # # Sharing external USB Disc # EPS=/mnt/HD_a2/EPS EPS_LOG=/mnt/HD_a2/EPS/eps.log if [ -f $EPS/usb-storage.ko ] then date > $EPS_LOG echo "*** Adding external USB drive ***" >> $EPS_LOG insmod $EPS/usb-storage.ko >> $EPS_LOG # wait a few seconds for the usb drive to be detected sleep 20 dmesg >> $EPS_LOG # Find out which disk is the 250GB # Substitute the : for 1 so /dev/sdx: becomes /dev/sdx1 fdisk -l | grep '250.0' | awk {'print $2'} | awk '{sub(":","1")}1' > /mnt/HD_a2/mntpt.log MNTPT=`cat /mnt/HD_a2/mntpt.log` # Make sure something was returned (-n is length non zero) if [ -n $MNTPT ] ; then if [ ! -d /mnt/usb250 ] ; then echo "Creating usb250 mount point" >> $EPS_LOG mkdir /mnt/usb250 >> $EPS_LOG else echo "/mnt/usb80 already exists" >> $EPS_LOG fi mount $MNTPT /mnt/usb250 >> $EPS_LOG fi fdisk -l | grep '80.0' | awk {'print $2'} | awk '{sub(":","1")}1' > /mnt/HD_a2/mntpt.log MNTPT=`cat /mnt/HD_a2/mntpt.log` if [ -n $MNTPT ] ; then if [ ! -d /mnt/usb80 ] ; then echo "Creating usb80 mount point" >> $EPS_LOG mkdir /mnt/usb80 >> $EPS_LOG else echo "/mnt/usb80 already exists" >> $EPS_LOG fi mount $MNTPT /mnt/usb80 >> $EPS_LOG fi # Now copy modified smb conf file to samba directory cp $EPS/smb.conf /etc/samba >> $EPS_LOG smb restart >> $EPS_LOG echo "*** Starting nfs server ***" >> $EPS_LOG # Now start the nfs server (now started as an executable in /ffp/etc/rc) # sh /ffp/start/unfsd.sh start fi
The ffp.log shows
*** Running /mnt/HD_a2/EPS/eps.sh ... *** awk: No such file or directory awk: No such file or directory *** Starting fdisk... fdisk -l Unable to open -l cat: /mnt/HD_a2/mntpt.log: No such file or directory mount: can't find /mnt/usb250 in /etc/fstab or /etc/mtab *** Starting fdisk... fdisk -l Unable to open -l awk: No such file or directory awk: No such file or directory cat: /mnt/HD_a2/mntpt.log: No such file or directory mount: can't find /mnt/usb80 in /etc/fstab or /etc/mtab * Running /mnt/HD_a2/starttwonky.sh ... /mnt/HD_a2/EPS/eps.sh
What have I missed please.?
TIA
Offline
For starters, when the script runs from the cron job it's running the wrong fdisk: /usr/bin/fdisk
and this fdisk version doesn't support -l
To check wheres the fdisk that's running when you run the script from command line:
which fdisk
and replace calling fdisk with the one from the output (probably "/ffp/sbin/fdisk", without the quotes).
It all happens because the PATH environment variable is set differently. When the script runs on startup the shell that executes the script is not an interactive shell and so it's startup procedure is a bit different.
Here's a reference for the shell: http://linux.die.net/man/1/ash (not newb-friendly, sorry). There's a sticky with some recommended reading for the Linux newbie.
Last edited by scaramanga (2011-05-27 00:05:32)
Offline
scaramanga,
That is it, your cracked it!!. I appear to have the same problem with awk (possibly grep as well?). For now I have hard coded the path to each command.
The path I have when I log in is '/ffp/sbin:/ffp/bin:/usr/sbin:/sbin:/usr/bin:/bin'
Could I change the path in the script to that using 'PATH=/ffp/sbin:/ffp/bin:/usr/sbin:/sbin:/usr/bin:/bin' or would that just cause more problems.
Would I perhaps need to add the current path at the end with 'PATH=/ffp/sbin:/ffp/bin:/usr/sbin:/sbin:/usr/bin:/bin:$PATH'.
At least it is working now, so many thanks for your help in getting there.
Offline
You can look at /ffp/etc/profile to see how the PATH variable is set.
Offline