2

I am trying to execute multiple commands in one shot but to my surprise only the first command is getting executed and the rest are skipped. And the command is

cleartool setview view1234 ; cleartool setactivity activity456 ; cd /vobs/app/src/epw/WEB-INF/scripts ; pwd

And the output of the above command is

You can now run 'clearquest' to start Rational ClearQuest.

But instead I'm expecting to see the following 3 lines of output:

You can now run 'clearquest' to start Rational ClearQuest.
Set activity "activity456" in view "view1234".
/vobs/app/src/epw/WEB-INF/scripts

My search efforts yielded few more variations for the same command by replacing semicolon(;) with ampersand (&) or pipe (|) but nothing seems to be working.

Any suggestions/ideas on how to run multiple commands like above?

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
Thulasi
  • 126
  • 3
  • 19
  • 2
    Try using `&&` instead of a single. – Matt Clark Aug 06 '15 at 20:54
  • Matt- The same result for &&. I mean only the first command gets executed and nothing after that. Even commands like pwd or ls doesn't work after view creation. – Thulasi Aug 06 '15 at 20:56
  • You're running that command from a shell prompt, right? If so, that should execute all three commands in sequence, assuming you have commands named `Cleartool` and `run`. How do you know the second and third commands aren't being executed? Try a simple example: `echo one ; echo two ; echo three' – Keith Thompson Aug 06 '15 at 20:58
  • @MattClark: That's not likely to help. The only difference `&&` would make is that the second and third commands *won't* run if a previous command fails. – Keith Thompson Aug 06 '15 at 20:59
  • Are any of those aliases to something else? `&&` works just fine for me to run multiple commands. – Matt Clark Aug 06 '15 at 21:00
  • @KeithThompson it may make a difference in this context. A single `&` will spawn the process in a background thread and move right into the next, where as the `&&` will wait for the prior to finish before beginning the next. – Matt Clark Aug 06 '15 at 21:01
  • @KeithThompson Your example will work. Because I tried running multiple commands like cd tesfolder && pwd && ls.. I see problm only when I run commands after set view command. Is there any time delay command available n unix so I can try running that time delay after view creation and try other commands a little later like 2000 ms. – Thulasi Aug 06 '15 at 21:04
  • @MattClark Thanks for the sleep command but it doesn't help me get out of this. Just adding one more interesting thing that I noticed. cmd2 && cmd3 && cmd4 is executing each command in order. where as cmd1 && cmd2 && cmd3 && cmd4 is just executing the first command. where cmd1 = Cleartool setview viewname cmd2 = cleartool setactivity activityName – Thulasi Aug 06 '15 at 21:12
  • As I already tried asking, is `Cleartool` an alias or sh function? Or a binary? Can you try running `echo $?` directly after cmd1? The output of this will be the return status code of the execution. A `0` will mean that everything preformed as expected, any other number will indicate an error, and `&&` will not continue. – Matt Clark Aug 06 '15 at 21:15
  • @MattClark: The OP said the second and third commands were *skipped*. Though I suspect that's not what's really happening. – Keith Thompson Aug 06 '15 at 21:25
  • @MattClark Cleartool is a command line interface for IBM's clearcase tool. It helps to get things like checkout, check in, etc I have tried to use your tip echo $? after my command but that doesn't print anything. It just prints the expected output after my command. Servername: cleartool setview user_app_web_05.50_int_unix && echo $? You can now run 'clearquest' to start Rational ClearQuest. – Thulasi Aug 06 '15 at 21:25
  • 1
    @user1423854: What happens if you run the commands one at a time: Run `Cleartool Setview viewname`, then run `Cleartool SetActivity activityname`, then run `run buildFile`. And again, do you really have a command called `run`? – Keith Thompson Aug 06 '15 at 21:26
  • `Cleartool setview user_app_web_05.50_int_unix && echo $?` -- That will do the `echo $?` only if the `cleartool` command succeeds. Change the `&&` to `;`, and it will show you the error status from the `Cleartool` command. (It's `Cleartool`, not `cleartool`, right?) – Keith Thompson Aug 06 '15 at 21:28
  • @KeithThompson 1) if I run all those commands one by one it works. 2) there is no such command but i typed in normal English. Instead if the command is even Cleartool Setview viewname && echo 1 && echo 2 The output is just "You can now run 'clearquest' to start Rational ClearQuest" and it is not printing 1 and 2. 3) It is cleartool and not Cleartool. – Thulasi Aug 06 '15 at 21:33
  • This is why copy-and-paste is *very* important. You're showing us a command that's superficially similar to the one that's actually failing. It's very likely that your summary has omitted whatever is causing the problem. Please update your question to show the **exact** copy-and-pasted command that's failing. If you're getting an error message, include that as well. – Keith Thompson Aug 06 '15 at 21:45
  • @KeithThompson I have modified my question and there is no error that I am seeing only the response to the first command is printed as a result of running multiple commands. – Thulasi Aug 06 '15 at 22:01
  • Do you get a shell prompt after running that command, or does the first sub-command hang? – Keith Thompson Aug 06 '15 at 22:15
  • yes I do get the shell prompt and I am once again typing in the second command manually to get it executed. – Thulasi Aug 06 '15 at 22:26

3 Answers3

3

Don't use cleartool setview: it forks the current shell in a subshell, which is why the rest is skipped when executed in a single line.
And which is why it works when executed one by one (the last two are executed in the subshell)

Always work with the full path of the dynamic view: /view/aview/vobs/avob/..., instead of setview (which you don't need).

If you must use cleartool setview, then use it with the -exec option (as in this answer):

cleartool setview -login -exec "command 1; command 2; command 3" view_tag

In your case:

cleartool setview -exec 'cleartool setactivity activity456 ; cd /vobs/app/src/epw/WEB-INF/scripts ; pwd' view1234 

Without setview:

The OP asks:

Say my view named humanbeing is in universe/planet/earth/humanbeing.vws

How do I use the startview command?
Is it something like

cleartool startview universe/planet/earth/humanbeing

or

cleartool startview cd universe/planet/earth/humanbeing

In both the cases it says the Error: Couldn't set view tag universe/planet/earth/humanbeing

To be sure, do a cleartool lsview -s | grep humanbeing: that will give you the view tag.

That should be:

cleartool startview humanbeing
cd /view/humanbeing/vobs/<avob>

universe/planet/earth/humanbeing.vws is the view storage, not a view tag.

Make sure that

  • is mounted (cleartool mount /vobs/avob)
  • myapp/WEB-INF/scripts is present in /view/humanbeing/vobs/<avob>

Don't try to do any symlink in /vobs: /vobs is a special MVFS (Multi-Version FileSystem) mounting point, not a regular folder.
Make sure your webapp search for apps in another path than /vobs.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Could you tell me how to get the full path of the dynamic view? I have an alias created for the dynamic (Integration) view and I am trying to set the view. – Thulasi Aug 06 '15 at 21:39
  • @user1423854 do not set the view. It only brings issue (read http://stackoverflow.com/a/10252612/6309). For an example of the full path, see http://stackoverflow.com/a/27826673/6309. Both links are in my answer. – VonC Aug 06 '15 at 21:40
  • I was able to find the myapp/WEB-INF/scripts folder under view/myview/myVOBS so now my problem is solved. – Thulasi Aug 16 '15 at 17:47
0

I'm not sure exactly what you are trying to do as it seems to be part of a larger problem space, but ...

cleartool setact -view view1234 activity456 

works to set an activity in the view, then

cd /view/view1234/vobs/app/src/epw/WEB-INF/scripts

will get you there. Or slap them together to get your result:

cleartool setact -view view1234 activity456 && cd /view/view1234/vobs/app/src/epw/WEB-INF/scripts && pwd

The statement <stmt1> && <stmt2> is shorthand for if [[ <stmt1> ]]; then <stmt2>

See KSH man page for more information on executing unix commands "in one shot".

A semicolon (;) causes sequential execution of the preceding pipeline; an ampersand (&) causes asynchronous execution of the preceding pipeline (i.e., the shell does not wait for that pipeline to finish). The symbol |& causes asynchronous execution of the preceding pipeline with a two-way pipe established to the parent shell; ... The symbol && ( | | ) causes the list following it to be executed only if the preceding pipeline returns a zero (non-zero) value.

Ian W
  • 4,559
  • 2
  • 18
  • 37
  • The `[[` in your pseudo-code is wrong, kind of. The `sh` (and thus also `ksh` and Bash) syntax is simply `if stmt1; then stmt2; fi` – tripleee Feb 02 '17 at 12:25
  • The pseudo code was not meant to be taken literally. Clarified. Nevertheless, it is preferred to place tests within [[ to avoid ambiguous results. Search SO for [[ vs [ for explanations – Ian W Feb 04 '17 at 07:22
  • Many beginners misunderstand the syntax of `if` and try exactly this on the false assumption that `[[` (or `[`) is part of the syntax; implying that this is correct is misleading them IMHO. See e.g. http://stackoverflow.com/questions/36371221/bash-if-statement-too-many-arguments for example. – tripleee Feb 04 '17 at 18:01
0

I don't have access to Clearcase to try things out but sometimes from past experience, you will need to RTFM, such tools with either accept a reverse pipe or an input script file, look in the documentation for syntax such as:

Cleartool < echo command_sequence

echo command_sequence | Cleartool - or

Cleartool -f inputfile or command sequence or

Cleartool -c inputfile or command sequence or

Cleartool run inputfile or command sequence or

If you do find some variant of the above does the trick please let us know by posting your own answer so that the next person with the problem can benefit.

Steve Barnes
  • 27,618
  • 6
  • 63
  • 73
  • None of those wouldn't work if the first cleartool command is 'setview': it forks the shell. – VonC Aug 07 '15 at 05:52
  • If you [RTFM](http://www-01.ibm.com/support/knowledgecenter/SSSH27_8.0.1/com.ibm.rational.clearcase.cc_ref.doc/topics/cleartool.htm?cp=SSSH27_8.0.1%2F4-0-0-0-0&lang=en), you'll see such options are not supported. – Ian W Aug 08 '15 at 23:32