MartyM Registered User
#1

Hi All

I'm new to boards.ie and posted this question in the "Programming" forum last night, having just found this forum, perhaps this is where I should have posted...

I'm having problems creating a simple shell script to execute 2 unix commands.

Basically, the commands are:

> cleartool setview myview
> source /vobs/mydir/...

Setting the clearcase view is causing the problem, this command seems to launch a subshell (i.e. the SHLVL environment variable is incremented), so the 2nd command does not get executed until I exit the subshell.

How do I get the 2nd command to execute in the subshell?

The commands must be in this order because the /vobs/... dir is not accessible without the clearcase view being set.

btw....I use tcsh

Any help with this would be great!

Cheers!

Blowfish Registered User
#2

Do you actually have to exit the subshell for the other command to work?

If not, how about just running it in the background. i.e.

> cleartool setview myview &
> source /vobs/mydir/...

You'd then have to add another command or two to kill the subshell though.

PMan Registered User
#3

MartyM
Hi All

I'm new to boards.ie and posted this question in the "Programming" forum last night, having just found this forum, perhaps this is where I should have posted...

I'm having problems creating a simple shell script to execute 2 unix commands.

Basically, the commands are:

> cleartool setview myview
> source /vobs/mydir/...

Setting the clearcase view is causing the problem, this command seems to launch a subshell (i.e. the SHLVL environment variable is incremented), so the 2nd command does not get executed until I exit the subshell.

How do I get the 2nd command to execute in the subshell?

The commands must be in this order because the /vobs/... dir is not accessible without the clearcase view being set.

btw....I use tcsh

Any help with this would be great!

Cheers!


My guess would be that cleartool is a shell script that exports a variable that your source command reads. Type "type cleartool" and open the file it references in vi to see what it is doing.
It could be that the cleartool script does not work in tcsh i.e. is bash specific.

MartyM Registered User
#4

Yeah....when running it in a script I have to exit the subhell before the 2nd command is executed. Here is what it looks like at the moment:

> test1.sh
[myview] > exit
exit
/vobs/mydir: No such file or directory.
Exit 1
>

# On exit from the subshell (myview prompt), the 'source' cmd is executed.

# Manually it should work like this:

> cleartool setview myview
[myview] > source /vobs/mydir


# I also tried your suggestion of running it in the background but it doesnt like that...

> test2.sh
[1] 25949
/vobs/mydir: No such file or directory.
Exit 1
>

MartyM Registered User
#5

PaschalNee
My guess would be that cleartool is a shell script that exports a variable that your source command reads. Type "type cleartool" and open the file it references in vi to see what it is doing.
It could be that the cleartool script does not work in tcsh i.e. is bash specific.



Cleartool works fine in tcsh......at least when the commands are issued manually!!

The cleartool file is an executable and unreadable...

PMan Registered User
#6

OK based on that I'd try

echo "source /vobs/mydir" | cleartool setview myview


or create a text file with your commands e.g.

source /vobs/mydir
blah blah 
blah 
exit


and do

cleartool setview myview < commands.txt

MartyM Registered User
#7

PaschalNee
OK based on that I'd try

echo "source /vobs/mydir" | cleartool setview myview


or create a text file with your commands e.g.

source /vobs/mydir
blah blah 
blah 
exit


and do

cleartool setview myview < commands.txt


Thanks for that but I'm afraid both suggestions returned nothing....the normal command prompt returned in both cases after about 3 seconds....even when I manually entered "cleartool setview myview < commands.txt"????

PMan Registered User
#8

>the normal command prompt returned in both cases after about 3 seconds
Sounds like it worked to me - what were you expecting to happen

MartyM Registered User
#9

Maybe someone knows another way around this?

The prerequisite for all of this is that I launch my xterms as follows:

xterm -sb -sl 10000 -title clearcase -bg lightgreen -e cleartool setview myview &

This launches my clearcase xterm, i.e.

[myview] > I then work away in clearcase...

Now I want to add a second arguement (source /vobs...), so when I launch my xterm I dont have to type it manually...

MartyM Registered User
#10

PaschalNee
>the normal command prompt returned in both cases after about 3 seconds
Sounds like it worked to me - what were you expecting to happen


I need my shell to enter clearcase mode....for want of a better description!

i.e.

> go from this prompt

[myview] > to this prompt

Basically, I need to continue working within clearcase after I have sourced my directory.....sourcing the directory is just setting up my environment.

MartyM Registered User
#11
PMan Registered User
#12

Expect might do the trick

expect -c "spawn cleartool setview myview; send \"source /vobs/mydir/\";interact " 


You can move the expect script into a file to get around needing to escape the double quotes.

MartyM Registered User
#13

PaschalNee
Expect might do the trick

expect -c "spawn cleartool setview myview; send \"source /vobs/mydir/\";interact " 


You can move the expect script into a file to get around needing to escape the double quotes.


I'm having problems executing this on the command line due to the double quotes.

I need to look at this for a while because I dont know expect at all and I'm not even sure if its setup in my work environment...

> type expect
expect not found

Thanks a lot!....and I'll let you know if I get it....

MartyM Registered User
#14

W@ Registered User
#15

Marty,

to do what you want, you have to perform the actions in the same way that a cronjob would. when trying to run cleartool via a script or external operator, you have to use the full path to perform the action such as:
/opt/rational/clearcase/etc/util/cleartool setview view /source/vobs/setup

I'm not sitting on a UNIX box at the moment, so I can't be positive of the actual location of the cleartool path, but I know it is in /opt/rational/clearcase somewhere. I've run builds by setting up my view this way then running the maven utility as a follow on.

If you want to pipe cleartool commands together, you could also use something similar to: for i in `cleartool command -options`; do cleartool command -options $i; done (i.e. "for i in `cleartool lsco -r -cview`; do cleartool ci -nc $i; done).

Want to share your thoughts?

Login here to discuss!