Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

hello !! I have a small db2 connect statement that works just fine from the command prompt on solaris.
ssh server 'for i in `. /u02/db2inst1/sqllib/db2profile;db2 list db di +rectory|grep "Database alias"|\ sed -e 's/Database//g' -e 's/alias//' -e 's/=//' `;do echo DB $i; . /u +02/db2inst1/sqllib/db2profile ; \ db2 connect to $i user tester using password ;db2 terminate ; +done ;'
Now when I put that in a perl script like this :
@test=`ssh $key '. /u02/db2inst1/sqllib/db2profile; for i in \`. /u02/ +db2inst1/sqllib/db2profile;db2 list db directory|grep "Database alias +"|sed -e 's/Database//g' -e 's/alias//' -e 's/=//' -e 's/\\n//g' \`;d +o echo DB \$i;db2 connect to $i user tester using password;done;'`;
I am getting an error saying user id and password incorrect.I think there is some syntax isseu but I am not sure. Please advice

Replies are listed 'Best First'.
Re: database connect
by zwon (Abbot) on Jul 28, 2009 at 17:49 UTC

    You didn't escape the last $ in statement

      Yes I did add the \ to the last $i db2 connect to \$i user tester using password But I still get the connect error. Is there anything else I am missing...?

        I wouldn't spend time trying to find things that need perl-escaping, since the end result becomes messy and hard to maintain. In stead consider moving the shell script to a (script)file and call it or move the logic in the script to perl.