Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 RT_SiteConfig.pm file. The relevant line in RT_SiteConfig.pm 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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.