LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-15-2008, 04:12 AM   #1
sanitynotvanity
Member
 
Registered: Jul 2007
Location: UK
Distribution: LFS 6.8, Android, Ubuntu 10.10, XP, 7 (HB,HP,Ultimate)
Posts: 41

Rep: Reputation: 15
Thumbs up 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.
 
Old 09-15-2008, 06:15 AM   #2
sanitynotvanity
Member
 
Registered: Jul 2007
Location: UK
Distribution: LFS 6.8, Android, Ubuntu 10.10, XP, 7 (HB,HP,Ultimate)
Posts: 41

Original Poster
Rep: Reputation: 15
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???
 
Old 09-15-2008, 02:08 PM   #3
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 46
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
 
Old 09-15-2008, 09:04 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
'login' doesn't work, 'su' doesn't work, can't login as root antiqui.populi Linux - Security 3 10-20-2006 05:32 PM
Gnome: Cannot login as default user, sends back to login, works as root Danny-T Linux - Newbie 2 05-27-2006 04:44 AM
XAWTV works, videodog works, motion works but how to code my own? rylan76 Linux - Hardware 0 01-06-2006 07:30 AM
Graphical login fail, text login works livewire98801 Linux - General 2 10-11-2004 07:09 PM
I have re-installed MK 9.2 but cannot login as user, login as root works. bobinglis Mandriva 2 02-22-2004 12:39 PM


All times are GMT -5. The time now is 03:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration