View previous topic :: View next topic |
Author |
Message |
BlackBart Apprentice
Joined: 07 Oct 2002 Posts: 252
|
Posted: Thu Jan 09, 2003 3:08 am Post subject: passing options at bootup |
|
|
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 |
|
|
alec Apprentice
Joined: 19 Apr 2002 Posts: 270 Location: Here
|
|
Back to top |
|
|
keratos68 Guru
Joined: 27 Dec 2002 Posts: 561 Location: Blackpool, Lancashire, UK.
|
Posted: Fri Jan 10, 2003 2:38 pm Post subject: |
|
|
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 |
|
|
BlackBart Apprentice
Joined: 07 Oct 2002 Posts: 252
|
Posted: Sat Jan 11, 2003 3:46 am Post subject: |
|
|
what should ARG i put in instead of arg, the argument i'm looking for. i.e. "scheme" or "scheme=home" |
|
Back to top |
|
|
keratos68 Guru
Joined: 27 Dec 2002 Posts: 561 Location: Blackpool, Lancashire, UK.
|
Posted: Sat Jan 11, 2003 8:31 pm Post subject: |
|
|
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 |
|
|
BlackBart Apprentice
Joined: 07 Oct 2002 Posts: 252
|
Posted: Sat Jan 11, 2003 9:24 pm Post subject: |
|
|
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 |
|
|
nbensa l33t
Joined: 10 Jul 2002 Posts: 799 Location: Buenos Aires, Argentina
|
Posted: Sat Jan 11, 2003 9:33 pm Post subject: |
|
|
You can use the script posted by dazzle68 to scan the arguments passed to the kernel at boot time. |
|
Back to top |
|
|
keratos68 Guru
Joined: 27 Dec 2002 Posts: 561 Location: Blackpool, Lancashire, UK.
|
Posted: Sat Jan 11, 2003 9:35 pm Post subject: |
|
|
Erm , well tat IS a bash script.
What does (from you r shell prompt):
output?? _________________ Someone told me that "..they only ever made one mistake...."
...and that's when they said they were wrong!! |
|
Back to top |
|
|
BlackBart Apprentice
Joined: 07 Oct 2002 Posts: 252
|
Posted: Sat Jan 11, 2003 10:11 pm Post subject: |
|
|
I found out the problem but not how to fix it. It is setting BOOTARGS to the string "cat /proc/cmdline" |
|
Back to top |
|
|
keratos68 Guru
Joined: 27 Dec 2002 Posts: 561 Location: Blackpool, Lancashire, UK.
|
Posted: Sat Jan 11, 2003 10:30 pm Post subject: |
|
|
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 |
|
|
BlackBart Apprentice
Joined: 07 Oct 2002 Posts: 252
|
Posted: Sun Jan 12, 2003 7:36 pm Post subject: |
|
|
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 |
|
|
keratos68 Guru
Joined: 27 Dec 2002 Posts: 561 Location: Blackpool, Lancashire, UK.
|
Posted: Sun Jan 12, 2003 7:59 pm Post subject: |
|
|
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 |
|
|
steveb Advocate
Joined: 18 Sep 2002 Posts: 4564
|
Posted: Sun Jan 12, 2003 8:06 pm Post subject: |
|
|
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 |
|
|
|