Reading selected lines from a param file

Hi all,

I have a question for the Gurus. I apologize if this has bee shared before but I couldn't find the link.

I am trying to read parameters from an external parameter file. What I m trying to achieve is read selected lines from an external parameter file into the script. for eg my param file is going to look like

Please feed the user information below
"abc"
Please feed the password information below
"password"
Please feed the table information below
"table"

Enclosed I quotes is the variable which User want to pass over and would be dynamically changed. I want to keep this file protected and call from a script as

Script.ksh has

User=$1
Pwd=$2
Table=$3

How do I pass the 2nd 4th and 6th line into the script from an external file. Can I create the .ini file to achieve it. Please let me know. Quick response is much appreciated.

Best regards..

"Keep this file protected" is the key bit of information here.

I assume you wish the contents of your parameter file to not be visiable to those that have execute permissions on the script - Right?

The best way to do this is using the sudo tool, is it installed on your system?

If it is, do you have permission to make changes to the /etc/sudoers, or can you get changes done by the sysadmin on your behalf?

If your param file is hardcoded, I mean if you always have the values on 2nd, 4th and 6th line you can use

  1. If you want to keep the quotes
 sed -ne '2 p' -e '4 p' -e '6 p' paramfilename 
  1. If quotes are not required
  sed -ne 's/"//g' -e '2 p' -e '4 p' -e '6 p' paramfilename 

about visibility of the file i am not sure what exactly you are trying to say...
you can set permission as 711 i.e. rwx--x--x

 chmod 711 paramfilename 

Sam05121988 - you cannot source a file that only has execute permissions.

One can use sudo to get around this as show below:

create a group secret_params
make your param file owned by root:secret_params with 640 permissions (rw-r----)
In sudoers allow your.script to be run by any user as group secret_params without password:

ALL  ALL = (:secret_params) NOPASSWD: /usr/local/bin/your.script

At the top of your script: switch to group secret_params if not already in it and then execute script again:

#!/bin/sh
id=$(id -gn)
if [ $id != "secret_params" ]
then
   exec sudo -g secret_params $0 $@
fi

As far as the format of the params file make it var="value"

var="testing var"
password="top_secret"

it can be sourced in the script directly eg:

# read parameter valuse
. /usr/local/lib/myscript.params
echo var=$var

Thanks a lot guys for the prompt response.
I will try the options offered By Chubler and Sam for reading the Parm file.Earlier I have executed the Follwing form of it

Parm.txt had following contents
User="abc"
Pwd="password"
Export $User $Pwd

And script.ksh has
User=$1
Pwd=$2

Then I executed script as

./script.ksh ./Parm.txt

But it didn't work earlier. Will try this new approach. I have changed the permissions on the file already as mentioned here and that's how I manage to keep it protected. I am not sure if sudo is installed on my system. Will try to identify and will work with solutions mentioned. Will be definitely updating here soon with the results. Please let me know if there is a solution otherwise.
Thanks again..