Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a Bash shell script to backup our Request Tracker (RT) MySQL database on a daily basis. Instead of hard-coding the MySQL database user's password in the shell script I'd like to parse it from RT's file. The relevant line in looks like this:

Set($DatabasePassword , 'db_pw_here');

What would be the "cleanest" way of extracting only the string "db_pw_here" given the line above?

share|improve this question
up vote 1 down vote accepted

The "cleanest" way would be to write some Perl code to use the RT API to extract the value of DatabasePassword. I don't have access to an RT instance right now to try this out but it shouldn't be terribly difficult.

You could probably integrate a one-line Perl program into your bash script to get the value, something like:

perl -MRT::Config -e 'print $RT::Config::DatabasePassword'

Please note that this command line is completely fictional. Read the docs to find the actual invocation.

Now, less clean but probably perfectly effective would be to use sed to extract the information:

sed -n "/Set(\$DatabasePassword/ s/.*'\([^']*\)'.*/\1/p"
share|improve this answer
Thank you very much. – Xhantar Oct 21 '11 at 9:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.