DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#1 2011-05-26 20:37:45

gasman
Member
From: Swansea,UK
Registered: 2009-06-23
Posts: 94

Permissions on startup script incorrect.?

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

Code:

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

Code:

# EPS directory path
EPS_SCRIPT=/mnt/HD_a2/EPS/eps.sh
echo $EPS_SCRIPT

where the other parameters are defined and

Code:

#
# 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

Code:

#!/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

Code:

*** 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


DNS-323 FW 1.08 (05/15/2009) HW:B1
2 * Seagate    ST3500630AS (500GB)  Fun_plug 0.5
DNS-323 FW 1.08  (12/18/2009) HW:B1
2 * Hitachi    HDS5C3020ALA632 (2TB)  Fun_plug 0.5

Offline

 

#2 2011-05-27 00:02:05

scaramanga
Member
Registered: 2010-08-04
Posts: 251

Re: Permissions on startup script incorrect.?

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)


DNS-323 HW Rev. C1 FW 1.10 fun-plug 0.5
2 x WD10EARS-00Y5B1 in Standard mode (LCC set to 5 min; Aligned to 4K)
Transmission with Transmission Remote GUI

Offline

 

#3 2011-05-27 11:28:12

gasman
Member
From: Swansea,UK
Registered: 2009-06-23
Posts: 94

Re: Permissions on startup script incorrect.?

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. big_smile


DNS-323 FW 1.08 (05/15/2009) HW:B1
2 * Seagate    ST3500630AS (500GB)  Fun_plug 0.5
DNS-323 FW 1.08  (12/18/2009) HW:B1
2 * Hitachi    HDS5C3020ALA632 (2TB)  Fun_plug 0.5

Offline

 

#4 2011-05-27 15:12:50

scaramanga
Member
Registered: 2010-08-04
Posts: 251

Re: Permissions on startup script incorrect.?

You can look at /ffp/etc/profile to see how the PATH variable is set.


DNS-323 HW Rev. C1 FW 1.10 fun-plug 0.5
2 x WD10EARS-00Y5B1 in Standard mode (LCC set to 5 min; Aligned to 4K)
Transmission with Transmission Remote GUI

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB