Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
init script not working (problem with password i... [solved]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Timmer
Guru
Guru


Joined: 24 Aug 2004
Posts: 369
Location: Duluth, MN, USA

PostPosted: Mon Jan 21, 2013 12:14 am    Post subject: init script not working (problem with password i... [solved] Reply with quote

I'm having trouble with an init script I'm trying to write. The four variables below are defined in a config file.

Code:

start-stop-daemon -S -b -m -d /usr/local/nc -p /var/run/vpn.pid -x /usr/local/nc/ncsvc -- -h ${host} -u ${username} -p ${password} -r Default-Realm -f ${certificate}


If I put the password into the command line instead of the the config file, it works. So I'm thinking that there must be something I'm missing to make the password translate properly. It's probably not helped that I have spaces, an apostrophe, and an exclamation point in my password, so if things aren't escaped just right, it would not work. Does anyone have any hints?


Last edited by Timmer on Tue Jan 22, 2013 11:45 pm; edited 1 time in total
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21431

PostPosted: Mon Jan 21, 2013 12:57 am    Post subject: Reply with quote

Quote your variables unless you have good reason not to do so. You have shell metacharacters in the password, so you must quote its expansion.
Back to top
View user's profile Send private message
666threesixes666
Veteran
Veteran


Joined: 31 May 2011
Posts: 1248
Location: 42.68n 85.41w

PostPosted: Mon Jan 21, 2013 1:04 am    Post subject: Reply with quote

in linux, you can use a variable like $1 or $0...

i think $1 would be like passing the command and then use anything after the command..... i mean like this

/usr/bin/exec password

/script -bla bla bla -password $1

to get your script to pass your password -password password if that makes any sense.... just planting seeds and giving ideas....
Back to top
View user's profile Send private message
Timmer
Guru
Guru


Joined: 24 Aug 2004
Posts: 369
Location: Duluth, MN, USA

PostPosted: Mon Jan 21, 2013 2:13 am    Post subject: Reply with quote

Hu wrote:
Quote your variables unless you have good reason not to do so. You have shell metacharacters in the password, so you must quote its expansion.


so like so?
Code:
-p "${password}"


I've never seen an example like that before...

[Edit]
Okay, so that worked. Is there a way to stick all of those parameters in another variable, so my execute line would look like this:
Code:
start-stop-daemon -S -b -m -d ${WORKING_DIR} -p ${PIDFILE} -x ${COMMAND} -- ${COMMAND_OPTS}
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21431

PostPosted: Tue Jan 22, 2013 2:24 am    Post subject: Reply with quote

666threesixes666 wrote:
in linux, you can use a variable like $1 or $0...

i think $1 would be like passing the command and then use anything after the command..... i mean like this

/usr/bin/exec password

/script -bla bla bla -password $1

to get your script to pass your password -password password if that makes any sense.... just planting seeds and giving ideas....
This does not seem to be relevant. His problem is unquoted expansion of a variable. It does not matter whether the variable is named or is a script argument, it needs to be quoted.

Timmer wrote:
so like so?
Code:
-p "${password}"
Yes.
Timmer wrote:
Okay, so that worked. Is there a way to stick all of those parameters in another variable, so my execute line would look like this:
Code:
start-stop-daemon -S -b -m -d ${WORKING_DIR} -p ${PIDFILE} -x ${COMMAND} -- ${COMMAND_OPTS}
GNU bash can do what you want. I do not recall whether the behavior is a GNU extension or is part of POSIX. Assuming that compatibility is not a concern, the syntax would be:
Code:
COMMAND_OPTS=( -p "$password" -u "$username" )
start-stop-daemon -S -b -m -d ${WORKING_DIR} -p ${PIDFILE} -x ${COMMAND} -- "${COMMAND_OPTS[@]}"
Back to top
View user's profile Send private message
Timmer
Guru
Guru


Joined: 24 Aug 2004
Posts: 369
Location: Duluth, MN, USA

PostPosted: Tue Jan 22, 2013 3:37 am    Post subject: Reply with quote

Hu wrote:
I do not recall whether the behavior is a GNU extension or is part of POSIX. Assuming that compatibility is not a concern, the syntax would be:
Code:
COMMAND_OPTS=( -p "$password" -u "$username" )
start-stop-daemon -S -b -m -d ${WORKING_DIR} -p ${PIDFILE} -x ${COMMAND} -- "${COMMAND_OPTS[@]}"


Thanks! That worked like a charm. I looked up that syntax since I was unfamiliar with it, and it appears that you're defining COMMAND_OPTS as an array of parameters, and then appending all the array elements to the end. Did I get that right?
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21431

PostPosted: Tue Jan 22, 2013 11:38 pm    Post subject: Reply with quote

Yes.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming 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