0

I am trying to lock the label type using korn shell script but I am not able to lock.
As I am new to Korn scripts can some one help me.

Here is my current code:

cmUsers="user1,user2";
myuserName=$ENV{LOGNAME};

#checking whether current user is part of cmUsers list or not.

if [[ "$cmUsers" =~ m/$myUserName/i ]]

# if user belongs to cmUsers list, then trying to lock the lable type,
# if it fails exiting the process, else printing the success message

  "ct lock -nuser \"$cmUsers\" lbtype:${label}@/vobs/admin_rec" ;then
    die"Unable to lock label type: \"${label}\"\n";
  else
    print "Label ${label} has been successfully locked by $cmUsers"
  fi
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
rohit
  • 1,329
  • 2
  • 8
  • 10
  • I tried to clean up your Q's formatting, but I don't get if `"ct lock -nuser ...."` is a cmd or part of the comment preceeding. Repaste from the plain text file and use the `{}` tool at the top left of the edit box (on highlighted text) to keep proper formatting for code/data/errorMsgs/etc. Good luck. – shellter Dec 14 '17 at 02:46
  • Also, learn to use http://shellcheck.net **before** you post your code here ;-) . When you use shellcheck, you need to include a proper "she-bang" line as the first line, in your case `#!/bin/ksh` . AND avoid the top 10 shell script beginner mistakes by reading https://stackoverflow.com/tags/bash/info multiple times. (most of these apply to `ksh` as well). Good luck. – shellter Dec 14 '17 at 02:47
  • 1
    Your second line looks somewhat Perl-ish; I think you just want `myuserName=$LOGNAME` (or just use `$LOGNAME` wherever you subsequently use `$myuserName`) if you are trying to access an environment variable. – chepner Dec 14 '17 at 15:18
  • 1
    In fact, *most* of your script looks like Perl. – chepner Dec 14 '17 at 15:19

1 Answers1

0

Beside the shebang, one simple tip is to avoid using an alias (ct) in a script: use the full command cleartool instead.
See also "Ksh Scripting" and "ksh class"

#!/bin/ksh
cmUsers="user1,user2";
myuserName=$ENV{LOGNAME};

#checking whether current user is part of cmUsers list or not.
if [[ "$cmUsers" =~ m/$myUserName/i ]]; then
    # if user belongs to cmUsers list, then trying to lock the lable type, 
    # if it fails exiting the process, else printing the success message
    cleartool lock -nuser \"$cmUsers\" lbtype:${label}@/vobs/admin_rec"
    if [ $? -ne 0 ]; then
        echo "CRITICAL: Unable to lock label type: \"${label}\""
        exit 1
    fi
    echo "Label ${label} has been successfully locked by $cmUsers"
fi

However, an expression like $ENV{LOGNAME} points to the fact it might not be ksh or any other shell, but rather ratperl (if you are using ClearCase 7.x or more): see "About ratlperl and its impact on cqperl and ccperl"

In which case, remove the shebang, and try executing your script with:

ccperl yourScript.pl 
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I included this script in the previous script(which creates the label type). When I try to run the script it shows me errors from my previous script lines. But again when I try to execute my previous script without adding it runs well. What do you think the may be? – rohit Dec 14 '17 at 22:08
  • @clearclase I think this script is not meant to be included. It is meant to be run as a standalone script. – VonC Dec 14 '17 at 22:21