amudelka has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I am trying to run some set of commands whenever newgrp command is run. Problem with newgrp is that it opens up a new shell. So I am trying to run some clearcase commands within newgrp by making use of here-doc. Now this works fine without me trying to guide the error into an error log. If I don't use the piping as I have done below, this works fine.

system ("newgrp ankoor <<BLAH\n cleartool setview -exec \"cleartool l +n -s $rtl_compiles_dir/$new_release $topsim_dir/SIMULIBS/vcsmx/$new_ +release\" $view_name \n 2>>$0.ERR") if (!$flag_link);

I want to find a way to make the above command work or a suitable alternative would do.

Replies are listed 'Best First'.
Re: system command with here-doc
by JavaFan (Canon) on Jan 02, 2012 at 14:14 UTC
    • Do you actually have a Perl question? Seems like a shell syntax issue to me.
    • I don't see any pipe.
    • Please use code tags to make your code readable.
    • I don't see the here docs terminator.
Re: system command with here-doc
by pvaldes (Chaplain) on Jan 02, 2012 at 14:59 UTC
    system ("newgrp ankoor <<BLAH\n cleartool setview -exec \"cleartool ln + -s $rtl_compiles_dir/$new_release $topsim_dir/SIMULIBS/vcsmx/$new_re +lease\" $view_name \n 2>>$0.ERR") if (!$flag_link);
    I want to find a way to make the above command work or a suitable alternative would do.

    Seems like a valid question to me. OP wants to be able to run this in perl (or to have a perl replacement to this command)...

    Don't know exactly in detail what this command does, but newgrp changes the current group ID during a login session, so this seems a problem related with to modify "$(" and/or "$)". You could find useful also POSIX::setgid() for this problem instead newgrp

    use POSIX qw(setgid); $my_new_group_id = POSIX::setgid();

    Another question is if your here-doc is correctly formated, I can see the start of the here-doc <<BLAH, but I can't find the last BLAH closing the here-doc

Re: system command with here-doc
by Khen1950fx (Canon) on Jan 02, 2012 at 15:23 UTC
    I agree with JavaFan. It's not really a Perl question, but the sg command will do essentially the same thing without starting another shell.

      I get really confused with the setgid and setuid. I need it for this one system command. The linking/checkin can only be done under that group. The below code works.

      ## system ("newgrp ankoor <<BLAH\n cleartool setview -exec \"cleartool ln + -s $rtl_compiles_dir/$new_release $topsim_dir/SIMULIBS/vcsmx/$new_re +lease\" $view_name \nBLAH\n 2>>$0.ERR") if (!$flag_link); ##

      Yes the BLAH should come at the end theoretically, but that somehow causes issues, along with the redirecting error. The linking which I am trying to do works out fine but I get some garbage along with that which I am trying to redirect it to a log, and not on the stdout which will make it look messy. Here's the system command output I get.

      ## stty: standard input: Inappropriate ioctl for device Link created: "/cdb/topsimaegis//SIMULIBS/vcsmx/LINK_DIR". BLAH: Command not found. 2: Command not found. ##

      As you see the redirecting also fails along with the label ending which goes unrecognized.

        Can anyone help me on this