Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Want to Create Unix group using perl script

by sierpinski (Chaplain)
on Mar 17, 2010 at 14:44 UTC ( #829194=note: print w/replies, xml ) Need Help??

in reply to Want to Create Unix group using perl script

To have the script run as root, you either need to be root when you execute it (or from root's crontab), or use sudo when the script is executed.

As almut said, use system commands for most of the work. Just plan out how you would do it on the command line, then wrap those commands in Perl using one of the many methods (system, exec, backticks)... which one you use depends on various things, like do you want the script to wait for that command to finish before continuing, etc. You can read up on those commands just about everywhere. The easiest way is to google 'perl <command>'.

/\ Sierpinski
  • Comment on Re: Want to Create Unix group using perl script

Replies are listed 'Best First'.
Re^2: Want to Create Unix group using perl script
by abhi.nitk2003 (Initiate) on Mar 18, 2010 at 08:21 UTC
    Hi, I got it. but I want my script just take group id (not group name) and if it exists then run chgrp,chmod g+s command as root.Basically my script is running under my cronjob but to run chmod , chgrp I need to become "root" first. so how should I do that
    abhishek~/perl ~> cat #!/usr/bin/perl $in=<STDIN>; ($name, $passwd, $gid, $members) = getgrgid($in); print "group name: $name \t group id: $gid \n"; if ( $in == $gid ) { print "Success\n"; #how to become "root" here.. exec ("chgrp -R $gid /home/abhishek/cpp") || die "could not do chgrp $ +!"; } else { print "Group id does not exists, you need to give the existing group i +d \n"; } abhishek~/perl ~>

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://829194]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2018-06-18 20:26 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (110 votes). Check out past polls.