Product instance full path /opt/wheredb2/Version Current instance Userid #### 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 = ) { 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;