Petryanu Petryanu - 2 months ago 8
Bash Question

How to find if a file/directory is checked out in clearcase using shell script

I am new to using clearcase. I have an assignment regarding this.

I have a file named Files.txt in unix, which contains a list of directory paths.

Example: Files.txt

/a/b/c/d
/e/f/g/
i/j/k/l/m/n


I want to find out, if the directories listed in the Files.txt is checked out or not. Can someone help me with a shell script(if there is a way, I am not sure) to find if the listed directories in the Files.txt are checked out or not.

I have tried this in unix command line,

Command: ct des d

Output:

directory version "d/@@/main/0"
created 2008-07-09T07:18:26+05:30 by Anna (anna1.dummy@abc)
Element Protection:
User : anna : rwx
Group: dummy : rwx
Other: : r-x
element type: directory


In this way, for Files.txt, it is difficult for me to parse through the output of "ct des directory_name" for each directory listed in the Files.txt and check if all the directories listed are checked out or not, because the Files.txt contains more than 100 directory paths.
Is there a simple way to check if the directories in the Files.txt is checkout or not?

Answer

You need to loop on every line of your File.txt, and for each one describe and grep for CHECKEDOUT.

#!/bin/sh

lines=$(cat Files.txt)
while read -r line; do
  # do your descr there
  cleartool descr -l ${line}|grep CHECKEDOUT
done <<< "${lines}

Another way is to look for all checkout out folders, and for each one grep it from the Files.txt.

cleartool find . -type d -exec 'cleartool describe -fmt "%En %Rf\n" "$CLEARCASE_PN"' | grep "CHECKEDOUT"