LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Code using GREP only works after login. Needs to work on boot up?? (http://www.linuxquestions.org/questions/programming-9/code-using-grep-only-works-after-login-needs-to-work-on-boot-up-669977/)

sanitynotvanity 09-15-2008 03:12 AM

Code using GREP only works after login. Needs to work on boot up??
 
Hi,

i've had this problem with grep for a few days. i just dont understand whats going on. When i run this code automatically at boot up it only half works. where as if i run it after boot it runs perfectly fine.

the code is supposed to retrieve an item from the KERNEL line.

my expected/desired result is hdl.



/etc/rc.local

Code:

#!/bin/sh -e

# comments etc

BMODE2=$(egrep -o 'mode=[a-Z]*' /proc/cmdline)
echo "BMODE2 = $BMODE2"
BMODE2=${BMODE2#\mode=}
echo "BMODE2 = $BMODE2

input
Code:

1) video=geodefb initrd=/boot/initrd.gz ramdisk_size=6666 root=/dev/ram0 rw splash=silent mode=hdl ip=172.16.103.100 BOOT_IMAGE=/boot/vmlinuz
2) vga=791 initrd=/boot/initrd.gz ramdisk_size=6666 root=/dev/ram0 rw splash=silent mode=hdl ip=172.16.103.100 BOOT_IMAGE=/boot/vmlinuz

output
Code:

1-auto)
BMODE = mode=
BMODE =

1-manual)
/etc/rc.local
BMODE = mode=hdl
BMODE = hdl

2-auto)
BMODE = mode=
BMODE =

2-manual)
/etc/rc.local
BMODE = mode=hdl
BMODE = hdl

auto means the code was run as per the Ubuntu boot process. rc.local is the last file that is run before login scripts.

manual means i typed /etc/rc.local to invoke the code after login.


any ideas at all?

Thanks in advance,

Andy.

sanitynotvanity 09-15-2008 05:15 AM

it seems to be the regular expression part of the Grep statement that is throwing it out.

the '[a-Z]*' is the bit that fails when the script is run during boot up.

i have a symbolic link to the script at S99 in rcS.d. so it gets run just before rc.local (pretty much).

perhaps the libraries or something for reg-ex have not been loaded at this point???

jan61 09-15-2008 01:08 PM

Moin,

are your sure, that at boot time the following prerequisites are defined?
1. Is your /bin/sh really the bash or is it a simple Bourne shell at boot time (you are using bash specific syntax)?
2. Is the egrep path defined in the PATH environment variable?

I'm not sure that the commands you use are really available. Try this:
1. Do a /bin/ls -l /bin/sh
2. Do a type egrep
within your script. Normally the path to egrep (on my system /usr/bin/egrep) is not defined for rc scripts.

Jan

ta0kira 09-15-2008 08:04 PM

Most of the time your $PATH won't include /usr/bin during initialization. Logging in corrects this. Try using /usr/bin/egrep.
ta0kira


All times are GMT -5. The time now is 06:11 PM.