0

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?

Xhantar
  • 1,042
  • 1
  • 8
  • 11

1 Answers1

1

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"
larsks
  • 43,623
  • 14
  • 121
  • 180