How do you change a user's primary unix group in a ColdFusion rsh command?

217 views Asked by At

We use an rsh command to check files into ClearCase:

<cfexecute name="C:\cygwin64\bin\rsh.exe"
    arguments="-n -l #USERNAME# #SERVER# ""cleartool setview -exec '#KSH_FILE# -user #USERNAME# -dir #VOB_DIRECTORY#' #CLEARCASE_VIEW#"" "
    timeout="180"
    variable="CHECKIN_FILE_CONTENT">
</cfexecute>

But are running into an issue where a user's primary unix group is set to a different group than the VOB the user is trying to check the file into.

I need to run a newgrp command right before executing the #KSH_FILE#

I was sure this would work:

<cfexecute name="C:\cygwin64\bin\rsh.exe"
    arguments="-n -l #USERNAME# #SERVER# ""newgrp #GROUP#; cleartool setview -exec '#KSH_FILE# -user #USERNAME# -dir #VOB_DIRECTORY#' #CLEARCASE_VIEW#"" "
    timeout="180"
    variable="CHECKIN_FILE_CONTENT">
</cfexecute>

But it keeps timing out.. no errors, just spins and stops.

---UPDATE--- Upon further testing, cfexcute and rsh don't seem to allow multiple commands. Here is a sample test I tried that yielded the same problems:

<cfexecute name="C:\cygwin64\bin\rsh.exe"
    arguments="-n -l #USERNAME# #SERVER# ""newgrp #GROUP#; id -a > results.txt"" "
    timeout="180">
</cfexecute>
2

There are 2 answers

2
Klog On BEST ANSWER

I ended up creating a launchcheckin.ksh script to change the user's group within the shell. I just pass the commands that I wanted to execute as arguments to the script, change the group in the script and execute the commands in the newgrp stream! We've had this out in production for 6 months without a hitch.

launchcheckin.ksh

FILE="$1"
GROUP="$2"
COUNT=1
for argument in $*
  do
    if [ ${COUNT} -gt 2 ]
      then
        ARGUMENTS="${ARGUMENTS} ${argument}"
      fi
    ((COUNT+=1))
done

newgrp ${GROUP} << EOF
${FILE} ${ARGUMENTS}
EOF

Updated command

<cfexecute name="C:\cygwin64\bin\rsh.exe"
    arguments="-n -l #USERNAME# #SERVER# ""cleartool setview -exec '/launchcheckin.ksh #KSH_FILE# #GROUP# #ARGUMENTS#' #CLEARCASE_VIEW#"" "
    timeout="180"
    variable="CHECKIN_FILE_CONTENT">
</cfexecute>
5
VonC On

Don't use (as I explained here) cleartool setview: it forks the current shell which is why the the newgrp and setview don't communicate well: they trigger their own shells.

If you need to do anything with a dynamic view, use its full path (/view/<aview>/vobs/<avob>), don't use setview. That way, you can use newgrp if you need to.