1

I am working on a script to create a clearcase view and perform some other functions.

In the setview function, when used inside a script, for performing operations on the view, the recommended command format is

cleartool setview -exec "commands" view_name

For the "commands" part, I want to use a function defined in the same shell script prior to this call. It seems it is not working when I do the following:

cleartool setview -exec "function_name(var1, var2)" view_name

So, the question I have is : can a function be used with "exec" command, and if it is possible, what is the syntax?

In one of the SO answers, it mentions not to use setview but to use startview. Since I don't know the difference between the two and I need to perform other actions in the script, I would appreciate any help, if I should not use setview exec mecxhanism.

The reason I am trying to use a function instead of another shell script called from the "exec" is that when using function, I do not have to export the variables that can be used by the called script, since the function is defined in the same script that is calling the setview command.

adbdkb
  • 1,897
  • 6
  • 37
  • 66
  • Do you mean the `bash` `exec` command, or the `-exec` option to `cleartool`? – cdarke Jul 09 '16 at 16:31
  • Without knowing much about how cleartool implements the `-exec` option, it seems unlikely that you would be able to use a shell function in that manner (or at all). Since cleartool is a separate utility and not part of shell, it does not have access to the shell environment and can only implement an exec option by creating a new subshell; in that subshell, the function would not be defined. (Bash lets you export functions to bash subshells, but there is no guarantee that the subshell started by cleartool uses bash. And even with that, you need to export everything, including the function.) – rici Jul 09 '16 at 17:05
  • @cdarke - I mean the `-exec` option to `cleartool` – adbdkb Jul 13 '16 at 01:31
  • @rici - I was able to define all the commands that I needed to the `-exec` option. As I mentioned in my earlier comment, I will explore how I can use the startview command as mentioned by @VonC . I may need to post additional questions, – adbdkb Jul 13 '16 at 01:37

2 Answers2

0

As I said repeatedly by the past, never use cleartool setview: it isn't worth it, as it creates (fork) a sub-shell which ,in your case, makes passing parameters quite difficult.
(those variables defined within the scripts won't be accessible in the forked sub-shell)

The only advantage of setview it the path of the mounted view, which starts always with /vobs/avob/...

cleartool startview makes sure the dynamic view is started, that is acccessible through its full path /view/aview/vobs/avob/...
See more at "How to run multiple Unix commands in one shot"

That way, your script remains very simple (but has to use the full path of the view, not /vobs/...):

cleartool startview aview
cd /view/aview(/vobs/avob/apth)

function_name(var1, var2)

assuming I do the startview approach, how can I find the view path after creating the view in my script?

The path of a dynamic view is always built the same way:

clearcase startview aViewX
cd /view/aViewX/
         ^^^^^^
cleartool lsview -l -pro aViewX -cview

That last command will give your the view storage path. (see "To find a view storage directory")

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you. What I really want to do is **create a view, copy the view and viewstorage files** to a NAS share ( I have been unable to "create the view" on NAS share ), and **delete the original view**. So, assuming I do the startview approach, how can I find the view path after creating the view in my script? Also, I presume, I shall have to do stopview before doing rmview. Is that correct assumption? – adbdkb Jul 09 '16 at 14:00
  • @adbdkb That is another question entirely. My answer was about your original question about how to use startview and a function in a bash script. Feel free to ask another question, with more details (your OS, your version of ClearCase) – VonC Jul 09 '16 at 14:36
0

@adbkdb On the "What I really want to do..." If you can't create the view, it would make more sense to determine why you can't create the view than to create+copy+remove process. There are specific requirements and a specific process to create a view with NAS-resident view storage.

If this is a UCM view, and the "copy" refers to the actual .vws directory (as opposed to a snapshot view workspace), then removing the view with rmview makes the copy effectively useless as the stream association is now broken.

Brian Cowan
  • 1,048
  • 6
  • 7
  • I know there are specific requirements and I am not able to make changes to the environment - not under my control. And all I really care about is being able to get the view files. I am able to do that using setview and using exec "" part for setview. So, in the interest of time and resource availability and willingness to change things, I am going to work with my original approach . But VonC's answer / recommendation is a valid alternative to doing too many things in the exec "" part ( reason I was trying to make a function call ) and I am going to see how to add it to my script. – adbdkb Jul 12 '16 at 22:30