Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
passing options at bootup
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
BlackBart
Apprentice
Apprentice


Joined: 07 Oct 2002
Posts: 252

PostPosted: Thu Jan 09, 2003 3:08 am    Post subject: passing options at bootup Reply with quote

I would like to be able to specify at bootup an environment variable as to what network configuration to use for the pcmcia cards. I.E. i would pass a command to the kernel which would set the value "location" and then i could have my scripts read the value of location and configure my network cards accordingly.
Back to top
View user's profile Send private message
alec
Apprentice
Apprentice


Joined: 19 Apr 2002
Posts: 270
Location: Here

PostPosted: Thu Jan 09, 2003 3:45 am    Post subject: Reply with quote

Not quite a kernel-land tool, but quickswitch (http://www.muthanna.com/quickswitch/) might be what you're looking for.
Back to top
View user's profile Send private message
keratos68
Guru
Guru


Joined: 27 Dec 2002
Posts: 561
Location: Blackpool, Lancashire, UK.

PostPosted: Fri Jan 10, 2003 2:38 pm    Post subject: Reply with quote

You can get access to the kernel boot flags by reading the /proc/cmdline file.

E.g. Create this script, make it executable and run it!!
Code:
#!/bin/bash
BOOTARGS=`cat /proc/cmdline`
for ARG in "$BOOTARGS";
do
   echo "Argument:  $ARG";
done

_________________
Someone told me that "..they only ever made one mistake...."

...and that's when they said they were wrong!!
Back to top
View user's profile Send private message
BlackBart
Apprentice
Apprentice


Joined: 07 Oct 2002
Posts: 252

PostPosted: Sat Jan 11, 2003 3:46 am    Post subject: Reply with quote

what should ARG i put in instead of arg, the argument i'm looking for. i.e. "scheme" or "scheme=home"
Back to top
View user's profile Send private message
keratos68
Guru
Guru


Joined: 27 Dec 2002
Posts: 561
Location: Blackpool, Lancashire, UK.

PostPosted: Sat Jan 11, 2003 8:31 pm    Post subject: Reply with quote

BlackBart wrote:
what should ARG i put in instead of arg



WHAT???
_________________
Someone told me that "..they only ever made one mistake...."

...and that's when they said they were wrong!!
Back to top
View user's profile Send private message
BlackBart
Apprentice
Apprentice


Joined: 07 Oct 2002
Posts: 252

PostPosted: Sat Jan 11, 2003 9:24 pm    Post subject: Reply with quote

i was wondering about the bash script, if i wanted to include that in a scirpt what should I put in for "ARG" I can't seem to get it to return anything no matter what i put in for "ARG"
Back to top
View user's profile Send private message
nbensa
l33t
l33t


Joined: 10 Jul 2002
Posts: 799
Location: Buenos Aires, Argentina

PostPosted: Sat Jan 11, 2003 9:33 pm    Post subject: Reply with quote

You can use the script posted by dazzle68 to scan the arguments passed to the kernel at boot time.
Back to top
View user's profile Send private message
keratos68
Guru
Guru


Joined: 27 Dec 2002
Posts: 561
Location: Blackpool, Lancashire, UK.

PostPosted: Sat Jan 11, 2003 9:35 pm    Post subject: Reply with quote

Erm , well tat IS a bash script.

What does (from you r shell prompt):
Code:
cat /proc/cmdline
output??
_________________
Someone told me that "..they only ever made one mistake...."

...and that's when they said they were wrong!!
Back to top
View user's profile Send private message
BlackBart
Apprentice
Apprentice


Joined: 07 Oct 2002
Posts: 252

PostPosted: Sat Jan 11, 2003 10:11 pm    Post subject: Reply with quote

I found out the problem but not how to fix it. It is setting BOOTARGS to the string "cat /proc/cmdline"
Back to top
View user's profile Send private message
keratos68
Guru
Guru


Joined: 27 Dec 2002
Posts: 561
Location: Blackpool, Lancashire, UK.

PostPosted: Sat Jan 11, 2003 10:30 pm    Post subject: Reply with quote

You are using the wrong quote character,


Use the back-quote ` and NOT one of ' or "
_________________
Someone told me that "..they only ever made one mistake...."

...and that's when they said they were wrong!!
Back to top
View user's profile Send private message
BlackBart
Apprentice
Apprentice


Joined: 07 Oct 2002
Posts: 252

PostPosted: Sun Jan 12, 2003 7:36 pm    Post subject: Reply with quote

o.k. thanx, next how would i get the only the agument following "scheme="? I red the manual for sed but it didn't seem like it could do that, any other things?
Back to top
View user's profile Send private message
keratos68
Guru
Guru


Joined: 27 Dec 2002
Posts: 561
Location: Blackpool, Lancashire, UK.

PostPosted: Sun Jan 12, 2003 7:59 pm    Post subject: Reply with quote

Code:
#!/bin/bash
ARGS=`cat /proc/cmdline`
for ARG in $ARGS ;
do
   
   if [ "${ARG:0:5}" = "scheme" ]
   then
   # Your "scheme" argument has been found.
      argval=${ARG#scheme=}
   # "argval" is now the value of X where "scheme=X"
      echo $argval
   fi

done


The bash builtin shell expansions "${XXX}" are well defined in "info" pages, see "info bash" then "Basic Shell Features"->"Shell Expansions"->"Shell Parameter Expansion"
_________________
Someone told me that "..they only ever made one mistake...."

...and that's when they said they were wrong!!
Back to top
View user's profile Send private message
steveb
Advocate
Advocate


Joined: 18 Sep 2002
Posts: 4564

PostPosted: Sun Jan 12, 2003 8:06 pm    Post subject: Reply with quote

BlackBart wrote:
o.k. thanx, next how would i get the only the agument following "scheme="? I red the manual for sed but it didn't seem like it could do that, any other things?


to get just one element, try (change scheme with the key you like to search for):
Code:
cat /proc/cmdline|sed -n "s/.*\(scheme=[^ ]*\).*/\1/gIp"


or use this one to list all of them:
Code:
for ARG in $(cat /proc/cmdline);do echo ${ARG}|sed -n "s/^\([^=]*\)=\([^ ]*\).*/ARG NAME: \1\nARG VALUE: \2/gIp";done


or you could use something like this:
Code:
#!/bin/bash

for ARG in $(cat /proc/cmdline)
do

  ARG_NAME=`echo ${ARG}|awk 'BEGIN{FS="="}{print $1}')`
  ARG_VALUE=`echo ${ARG}|awk 'BEGIN{FS="="}{print $2}')`

  case "${ARG_NAME}" in
    switch1)
      echo "NAME: ${ARG_NAME}"
      echo "VALUE: ${ARG_VALUE}"
      ;;
    switch2)
      echo "NAME: ${ARG_NAME}"
      echo "VALUE: ${ARG_VALUE}"
      ;;
    switch3)
      echo "NAME: ${ARG_NAME}"
      echo "VALUE: ${ARG_VALUE}"
      ;;
  esac

done


or if you like, you could use if/elif statements:
Code:
#!/bin/bash

for ARG in $(cat /proc/cmdline)
do

  if (echo ${ARG}|grep -q -i "^switch1=");then
    # switch1 flag is set...
  elif (echo ${ARG}|grep -q -i "^switch2=");then
    # switch2 flag is set...
  elif (echo ${ARG}|grep -q -i "^switch3=");then
    # switch3 flag is set...
  elif (echo ${ARG}|grep -q -i "^switch4=");then
    # switch4 flag is set...
  elif (echo ${ARG}|grep -q -i "^switch5=");then
    # switch5 flag is set...
  elif (echo ${ARG}|grep -q -i "^switch6=");then
    # switch6 flag is set...
  fi

done


cheers

SteveB
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum