Clearcase running commands from a script (error: Bad phone number) - clearcase

I have a small shell titled xrunner.sh.
#!/bin/bash
ct checkout -nc parentFolder
cd parentFolder/
ct mkdir -nc directory
ct checkin -nc directory
cd ..
ct checkin -nc parentFolder
pwd
When the commands are run individually on the CLI they all work fine, When run from the bash however the following is thrown back at me:
ct: bad phone number -- parentFolder
ct: bad phone number -- -nc
ct: bad phone number -- checkout
: No such file or directory
ct: bad phone number -- directory
ct: bad phone number -- -nc
ct: bad phone number -- mkdir
ct: bad phone number -- directory
ct: bad phone number -- -nc
ct: bad phone number -- checkin
: No such file or directory
ct: bad phone number -- parentFolder
ct: bad phone number -- -nc
ct: bad phone number -- checkin
Would anyone happen to know why this is or point me to some web reference that explains this?

That means you don't have defined the alias 'ct' properly
add:
alias ct=/path/to/cleartool
Note: if you want to add a directory to source control, don't forget to call mkelem
cleartool mkelem -mkpath dir1 -c "a comment"
See "Command line add to Source control of a directory with files in a dynamic view returns Error".
Notes:
as this thread suggests, even if the alias is already defined, a ct setview won't allow further ct commands to work, because setview spawns a sub-shell. See for instance "Python and ClearCase setview" for more on setview.
So ct will work, except if you have further ct commands in a script after a ct setview.
Just for information, here the the man page for the /usr/bin/ct command
ct(1)
NAME
ct - spawn getty to a remote terminal (call terminal)
The UNIX command "/usr/bin/ct" dials a phone number, where a modem connected to a terminal should be awaiting for the call, and then spawns a getty(1M) process to that terminal.
The "getty" process sets the terminal type, modes, speed and line discipline, and then invokes the "login" process, which in turn will execute a shell when a user authenticates correctly.

The problem you get with ct: bad phone number... is because there is actually another binary called ct. You can run type -p ct in bash to find which (too many years since I had the same problem so I do not remember where it was (/usr/xpg4/bin ??)).
So as VonC suggest, make an alias for ct.

Related

Not able to checkout elements in stream in ClearCase

I am not able to checkout any element in Dev stream in Clearcase from any user except the admin user. I am getting below error :
No permission to perform operation "checkout".
Must be one of: member of object group, object owner, VOB owner, member of admin group.
I added the user group to the Primary group of clearcase in Windows, but I am still facing same issue.
Assuming a regular ClearCase (not CCRC with automatic or web view), type in your view:
cleartool lsview -l -full -pro -cview
Check if if the primary group is correct.
If not, take note of the global path (which should be like an network UNC path \\<aServer>\path\to\view\storage.
If not, in a regular CMD session:
set CLEARCASE_PRIMARY_GROUP=<aGroup>
doskey fp=c:\Rational\ClearCase\etc\utils\fix_prot.exe -force -chgrp "<aGroup>" -chown <aLogin> $*
fp -rec -chmod 775 \\UNC\Path\to\view.vws
fp -root \\UNC\Path\to\view.vws
Replace \\UNC\Path\to\view.vws by the global path you have seen in the first step (the lsview one), as mentioned above.
Replace <aGroup> by the primary group name, and <aLogin> by your Windows login.
Make sure your user is part of that group.

Clearcase CASE INSENSITIVITY

I am trying to write a windows batch file to automate the checkout/check-in process for the ClearCasr tool but facing an issue with Case letters of the file name.
For example: if filename is "Hello_Working.txt" when I copied to my vob its becoming "hello_working.txt".
So when I do a checkout/check-in its prompting error as "Pathname not found".
I know MVFS "Clear Preserve" will solve the problem but if we change the setting other vobs which are running will affect, My admin suggested that your batch file script commands has to negotiate the cases of the file name. I am writing the command as below
Checkout:
ct co -nc H:\test1_view\test1_vob\Hello_working.txt
ct co -cfile "Comment"
Checkin:
ct ci -nc H:\test1_view\test1_vob\Hello_working.txt
ct ci -cfile "Comment"
Please let me know what needs to modify in the commands?
First, you don't have to co/ci -nc, and then co/ci -cfile "comment".
You can checkout with comment, and then ci -nc: a checkin without comment will use by default the comment given in the checkout step.
ct co -c "Comment" H:\test1_view\test1_vob\Hello_working.txt
ct ci -nc H:\test1_view\test1_vob\Hello_working.txt
Second, you can try checkin all the checked-out files, as in "Recursive checkin using Clearcase", which would make ClearCase find the right name (even when the filename is converted to lowercase in Windows dynamic view).
ct lsco -r -cvi -fmt "ci -nc \"%n\"\n" | ct
Even for one file, try the command ct lsco (cleartool lscheckout) in order to ask ClearCase for the right name.

Trying to undo a cleartool rm

I was trying to migrate a file from directory A to directory B in a branch, call it file.txt. What I did was:
cd A
cp file.txt ../B/
ct rm A
cd ../B
ct mkelem -ci -nc file.txt
Thereby losing all the history. I am trying to recover from this to do what I should have done which is simply ct mv file.txt ../B
I read that for this I should do something like this:
cd A
ct ln .##/main/?/file.txt ./file.txt
where luckily, from another view, I've figured out ? should be 27. Unfortunately when I try to do the above I get:
cleartool: Error: Entry named "file.txt" already exists.
cleartool: Error: Unable to create link: "./file.txt".
and I try to do:
ct rmelem file.txt
but got:
cleartool: Error: Element "file.txt" has branches not created by user
though presumably that's not what I should be doing anyway. How do I get back that file? It was simply a ct rm. I even get the entry already exists error if I do ct rm on the new copy file I added to directory B..
You are on the right track, but I would recommend a simple rmname, instead of a rmelem (which deletes the element with all its versions, branches and such).
That would remove file.txt from the latest version of the parent directory, and allows you to proceed with the symlink.
Next time, a cleartool mv might be easier, and keep the history of the file being moved.

Clearcase: List labels matching a particular string

I would like to list the available labels matching a particular string applied in the view.
I confirm a filter in cleartool find is not possible:
ct find . -ele "lbtype_sub(My_LAB*)" -print
would not work (no wildcard in query argument.
If you cannot use a grep in a shell pipe, can you consider using grep in an exec part of a find, like in this example?
ct find . -kind lbtype -exec "echo %CLEARCASE_PN%|grep MY_LAB"
If this is not acceptable, you need to write the result in a file and process it with another tool (sed?)
You have packages for Windows including Unix commands: see this SO question.
Of you have freeware emulating the grep command.
If you must stay with native Windows commands, you must redirect the result in a file, and use FIND (English translation).
Hmm. I'm not entirely sure about this although the following will list all labels used for a given VOB (entered using ClearTool command line application).
lstype -kind lbtype -invob vob_path_and_name -short
for example with a View mapped to drive U: VOB "Some_VOB" would be:
lstype -kind lbtype -invob U:\Some_VOB -short

Recursive checkin using Clearcase

I want to check in a directory and all the sub-directories into the clear case.
Is there a specific command to achieve it?
Currently I am going into each directory and manually checking in each file.
I would recommend this question:
Now the problem is to checkin everything that has changed.
It is problematic since often not everything has changed, and ClearCase will trigger an error message when trying to check in an identical file. Meaning you will need 2 commands:
ct lsco -r -cvi -fmt "ci -nc \"%n\"\n" | ct
ct lsco -r -cvi -fmt "unco -rm %n\n" | ct
(with 'ct being 'cleartool' : type 'doskey ct=cleartool $*' on Windows to set that alias)
But if by "checkin" you mean:
"enter into source control for the first time"
"updating a large number of files which may have changed on an existing versionned directory"
I would recommend creating a dynamic view and clearfsimport your snapshot tree (with the new files) in the dynamic view.
See this question or this question.
the clearfsimport script is better equipped to import multiple times the same set of files, and automatically:
add new files,
make new version of existing files previously imported (but modified in the source set of files re-imported)
remove files already imported but no longer present in the source set of files.
make a clear log of all operations made during the import process.
:
clearfsimport -preview -rec -nset c:\sourceDir\* m:\MyView\MyVob\MyDestinationDirectory
did you used -recurse option in the clearfsimport command.
Example: clearfsimport -recurse source_dir .
This should help.
If you're using the Windows client, right-click on the parent folder, select Search, leave the file name field empty, click Search, select all the files in the result window (ctrl-A), right-click on them and select ClearCase -> Add to Source Control
If you are in windows you may try,
for /f "usebackq" %i in (`cleartool lsco -cview -me -r -s`) do cleartool ci -nc %i

Resources