Hello Monks Sorry for my babyperl , I had happy perl learning, but I find a little Wtf! issue. I try to get db2versions, db2instances and list of data bases without modules. I have The "root powEr!" but When I trying "su - $user -c 'command to get DB list' " I get some like this.
but the command doesn't executeProduct instance full path /opt/wheredb2/Version Current instance Userid
This is my code ...
use warnings; use diagnostics; use strict; use 5.010; use Cwd; use DB2::Admin::Constants; ############################## + + + + ###Get Version and instances## + + + + ############################## + + + + sub check_for_instance{ open(EXEC, '-|', 'db2ls | awk \'!/Install/ && !/----/ \'') +or die "Can't exec: $!\n"; # Now read the output just like a file + + + + while(my $line = <EXEC>) { chomp $line; if($line=~/(\/db2\/V\d.\d+)/){ print "Product instance full path\n $`"."$1\n"; foreach ($line) { my $Path="$`"."$1"."/instance/"; chdir($Path) or die "Cant chdir to $Path $!"; my $dir = getcwd; open my $cmd, '-|', './db2ilist'; while ($line = <$cmd>) { say "Current instance \n$line"; my $user="$line"; my $action="db2 list db directory"; ######################### ### This doesn't works # ######################### system ("su -l - $user -c \'$action > DBlist.txt && cat + DBlist.txt\'"); ########################### # # # this works ! XD # ########################### #system ("su -l - MyRealuser -c \'$action > DBlist.txt && cat DBlist. +txt\'"); ####### } close $cmd; } } } close(EXEC); } &check_for_instance;
btw ,I tried to use sudo - $user -c 'command', sudo su - $user "command", sudo - $user -c "command". but when i use directly the userid su - "Myrealuser" 'comman' works as i waiting.
I hope someone can give me some light
In reply to run shell command as another user by ox1d0
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |