For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > November 2005 > Execute newgrp system command









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Execute newgrp system command
Suvajit Sengupta

2005-11-21, 7:56 am

Hi,
I want to login into a new group using 'newgrp' UNIX command.Every
newgrp command invokes a new shell.
But when I am trying to execute this system command from a perl script
the script is terminating and returning the prompt of the new shell .
Can anyone suggest on what can be done to change into a new group from
within perl script?

Regards,
Suvajit

Marcel

2005-11-21, 7:56 am

Have you tried usermod?

Marcel

Shawn Corey

2005-11-21, 7:56 am

Suvajit Sengupta wrote:
> Hi,
> I want to login into a new group using 'newgrp' UNIX command.Every
> newgrp command invokes a new shell.
> But when I am trying to execute this system command from a perl script
> the script is terminating and returning the prompt of the new shell .
> Can anyone suggest on what can be done to change into a new group from
> within perl script?


Short answer: You can't.

Long answer:

The newgrp command will always run a new shell regardless if it succeeds
or fails. What you can do instead is set the effective group id for the
script.

1. Change the script's group to the group you want it to work under (see
`man chgrp`).

2. Change the script's "set group id on execution" flag (see `chmod`).

The script will now run under the new group.

See `perldoc perlvar` and search for $) and $(.



--

Just my 0.00000002 million dollars worth,
--- Shawn

"Probability is now one. Any problems that are left are your own."
SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_
Suvajit Sengupta

2005-11-22, 3:56 am

Hi,
Thanks for the suggestion.
There are some tasks which are directly tied to the group-id. Owing to
the requirement it may happen my perl script need to switch groups to
achieve a specific task. So my plan is to change to a new group with new
grp command after exporting the Environment/required variables from the
current shell.
After the newgrp system command from a perl script could not satisfy my
need I tried including the command in a separate .cshrc file and then
just sourcing that file from a perl script. But this job could not again
be executed from perl script . The perl script returns error telling the
sourced file could not be found.
Moreover changing the scripts group permission wont do hold good for my
case.
I am at bay now !!

Regards,
Suvajit

Shawn Corey wrote:

> Suvajit Sengupta wrote:
>
>
>
> Short answer: You can't.
>
> Long answer:
>
> The newgrp command will always run a new shell regardless if it
> succeeds or fails. What you can do instead is set the effective group
> id for the script.
>
> 1. Change the script's group to the group you want it to work under
> (see `man chgrp`).
>
> 2. Change the script's "set group id on execution" flag (see `chmod`).
>
> The script will now run under the new group.
>
> See `perldoc perlvar` and search for $) and $(.
>
>
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com