Boards.ie uses cookies. By continuing to browse this site you are agreeing to our use of cookies. Click here to find out more x
Post Reply  
 
 
Thread Tools Search this Thread
27-04-2007, 10:51   #1
MartyM
Registered User
 
Join Date: Apr 2007
Posts: 262
Simple shell script to execute 2 unix cmds

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!
MartyM is offline  
Advertisement
27-04-2007, 10:56   #2
Blowfish
Registered User
 
Blowfish's Avatar
 
Join Date: Feb 2006
Location: /dev/null
Posts: 4,317
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.
Blowfish is offline  
27-04-2007, 11:01   #3
PMan
Registered User
 
PMan's Avatar
 
Join Date: Oct 2003
Posts: 1,339
Quote:
Originally Posted by 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.
PMan is offline  
27-04-2007, 11:20   #4
MartyM
Registered User
 
Join Date: Apr 2007
Posts: 262
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 is offline  
27-04-2007, 11:30   #5
MartyM
Registered User
 
Join Date: Apr 2007
Posts: 262
Quote:
Originally Posted by 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...
MartyM is offline  
Advertisement
27-04-2007, 11:30   #6
PMan
Registered User
 
PMan's Avatar
 
Join Date: Oct 2003
Posts: 1,339
OK based on that I'd try

Code:
echo "source /vobs/mydir" | cleartool setview myview
or create a text file with your commands e.g.

Code:
source /vobs/mydir
blah blah 
blah 
exit
and do

Code:
cleartool setview myview < commands.txt

Last edited by PMan; 27-04-2007 at 11:35.
PMan is offline  
27-04-2007, 11:42   #7
MartyM
Registered User
 
Join Date: Apr 2007
Posts: 262
Quote:
Originally Posted by PaschalNee
OK based on that I'd try

Code:
echo "source /vobs/mydir" | cleartool setview myview
or create a text file with your commands e.g.

Code:
source /vobs/mydir
blah blah 
blah 
exit
and do

Code:
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"????
MartyM is offline  
27-04-2007, 11:56   #8
PMan
Registered User
 
PMan's Avatar
 
Join Date: Oct 2003
Posts: 1,339
>the normal command prompt returned in both cases after about 3 seconds
Sounds like it worked to me - what were you expecting to happen
PMan is offline  
27-04-2007, 11:58   #9
MartyM
Registered User
 
Join Date: Apr 2007
Posts: 262
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 is offline  
Advertisement
27-04-2007, 12:03   #10
MartyM
Registered User
 
Join Date: Apr 2007
Posts: 262
Quote:
Originally Posted by 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 is offline  
27-04-2007, 13:27   #11
MartyM
Registered User
 
Join Date: Apr 2007
Posts: 262
similar problem described here.....no satisfactory workaround for me...yet!!

http://www-1.ibm.com/support/docview...=ct984rational
MartyM is offline  
27-04-2007, 13:56   #12
PMan
Registered User
 
PMan's Avatar
 
Join Date: Oct 2003
Posts: 1,339
Expect might do the trick

Code:
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.
PMan is offline  
27-04-2007, 14:45   #13
MartyM
Registered User
 
Join Date: Apr 2007
Posts: 262
Quote:
Originally Posted by PaschalNee
Expect might do the trick

Code:
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 is offline  
27-04-2007, 16:24   #14
MartyM
Registered User
 
Join Date: Apr 2007
Posts: 262
Thanks PaschalNee for all your help....I still didnt get around to the expect but will definitely give it a go!!

Ideally I wanted to remain in the clearcase envornment and have the
equivalent of the following from the command line:

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

[myview] > Then continue working
[myview] > within the clearcase environment
[myview] > and within the subshell spawned by the cleartool command


However, the 2nd workaround on that site was sufficient.....for now!

http://www-1.ibm.com/support/docview...=ct984rational

The following script allows me to set my view, source the vob and execute a
command within the clearcase environment.

The downside is that I dont remain in the clearcase environment.

The upside is that I dont have to "enter" the clearcase environment when
using the alias!


Code:
#!/bin/tcsh

# This script allows the user to run the 'extractinfo' command from the vobs
# without having to set their view or source /vobs/setup manually.

# The script is executed with the following command:
#
#	cleartool setview -exec ~<user>/bin/source_extractinfo.sh myview
# 
# OR with the alias 'lminfo' defined in ~<user>/.aliases

# Source vobs so that the extractinfo utility can be used to extract LM information
source /vobs/setup

# Prompt the user to enter the location and name of the LM
echo "Enter: /path/to/loadmodule"

# Read user input from stdin
set LM = $<

echo "Performing 'extractinfo' on the following LM: $LM..."

# Run the 'extractinfo' command to extract the LM info
extractinfo $LM
MartyM is offline  
10-02-2009, 20:51   #15
W@
Registered User
 
Join Date: Feb 2009
Posts: 2
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).
W@ is offline  
Post Reply

Quick Reply
Message:
Remove Text Formatting
Bold
Italic
Underline

Insert Image
Wrap [QUOTE] tags around selected text
 
Decrease Size
Increase Size
Please sign up or log in to join the discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Share Tweet