View previous topic :: View next topic |
Author |
Message |
Timmer Guru
Joined: 24 Aug 2004 Posts: 373 Location: Duluth, MN, USA
|
Posted: Mon Jan 21, 2013 12:14 am Post subject: init script not working (problem with password i... [solved] |
|
|
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 |
|
|
Hu Administrator
Joined: 06 Mar 2007 Posts: 21709
|
Posted: Mon Jan 21, 2013 12:57 am Post subject: |
|
|
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 |
|
|
666threesixes666 Veteran
Joined: 31 May 2011 Posts: 1248 Location: 42.68n 85.41w
|
Posted: Mon Jan 21, 2013 1:04 am Post subject: |
|
|
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 |
|
|
Timmer Guru
Joined: 24 Aug 2004 Posts: 373 Location: Duluth, MN, USA
|
Posted: Mon Jan 21, 2013 2:13 am Post subject: |
|
|
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?
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 |
|
|
Hu Administrator
Joined: 06 Mar 2007 Posts: 21709
|
Posted: Tue Jan 22, 2013 2:24 am Post subject: |
|
|
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? | 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 |
|
|
Timmer Guru
Joined: 24 Aug 2004 Posts: 373 Location: Duluth, MN, USA
|
Posted: Tue Jan 22, 2013 3:37 am Post subject: |
|
|
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 |
|
|
Hu Administrator
Joined: 06 Mar 2007 Posts: 21709
|
Posted: Tue Jan 22, 2013 11:38 pm Post subject: |
|
|
Yes. |
|
Back to top |
|
|
|