Sylvain masnada wrote: > > Hi again and thx John for you help. > > > > You could run id inside your perl program. > > > > my $id_output = qx/id/; > I didn't know how to execute a shell command into a perl script, thx.
There are many ways to execute a "shell command" in a perl program, that is just one way. > > > My script is : > > > > > > while(<>) > > > { > > > if(/^uid=\d+.\w+.\sgid=(\d+)/) > > > { > > > $gid=$1; > > > print "gid:$gid\n"; > > > } > > > } > > > > Perl supplies the User ID in $<, the Effective User ID in $>, the Group > > ID in $( and the Effective Group ID in $). > > What's the difference between effective and non-effective, It is the difference between the effective and the real uid/gid. > the answer are the same for : print > "$>, $<\n" and idem for group > Moreover when I do this > print "gid: $)\n"; > I get (a : gid: 0 10 6 4 3 2 1 0 > not just 0. How to get just the true gid? perldoc perlvar [snip] $REAL_GROUP_ID $GID $( The real gid of this process. If you are on a machine that supports membership in multiple groups simultaneously, gives a space separated list of groups you are in. The first number is the one returned by getgid(), and the subsequent ones by getgroups(), one of which may be the same as the first number. However, a value assigned to `$(' must be a single number used to set the real gid. So the value given by `$(' should *not* be assigned back to `$(' without being forced numeric, such as by adding zero. (Mnemonic: parentheses are used to *group* things. The real gid is the group you *left*, if you're running setgid.) $EFFECTIVE_GROUP_ID $EGID $) The effective gid of this process. If you are on a machine that supports membership in multiple groups simultaneously, gives a space separated list of groups you are in. The first number is the one returned by getegid(), and the subsequent ones by getgroups(), one of which may be the same as the first number. Similarly, a value assigned to `$)' must also be a space-separated list of numbers. The first number sets the effective gid, and the rest (if any) are passed to setgroups(). To get the effect of an empty list for setgroups(), just repeat the new effective gid; that is, to force an effective gid of 5 and an effectively empty setgroups() list, say ` $) = "5 5" '. (Mnemonic: parentheses are used to *group* things. The effective gid is the group that's *right* for you, if you're running setgid.) `$<', `$>', `$(' and `$)' can be set only on machines that support the corresponding *set[re][ug]id()* routine. `$(' and `$)' can be swapped only on machines supporting setregid(). > > print "gid: $(\n"; > > > > > > To find the name assigned to $(: > > > > my $group = getgrgid $(; > > print "Group: $group\n"; > > > > > > To get all groups that $( belongs to: > > > > my @groups; > > my $name = getpwuid $<; > > while ( my @ent = getgrent ) { > > push @groups, $ent[ 0 ] if $ent[ -1 ] =~ /\b$name\b/; > > } > > print "@groups\n" > > > > > > > My aim is to change the ip address following the gid. > > > > The id program does not output an ip address. > Yes I know. My first goal was to get the gid. Now I want to attribute ip address by > gid, maybe > thanks to : > > if ($( == 1000) > { > qx/ifconfig eth0 x.x.x.x up/; > } > > elseif ($( == 1001) > { > qx/ifconfig eth0 x.x.x.y up/; > } You should use system() instead of qx// for that. my %gid2ip = ( 1000 => 'x.x.x.x', 1001 => 'x.x.x.y', ); my @ifconfig = ( 'ifconfig', 'eth0', '', 'up' ); if ( exists $gid2ip{ $( + 0 } ) { $ifconfig[ 2 ] = $gid2ip{ $( + 0 }; system( @ifconfig ) == 0 or die "system @ifconfig failed: $?" } perldoc -f system John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]