Computing.Net > Forums > Unix > C shell unix script file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C shell unix script file

Reply to Message Icon

Name: Qiaozhen Mu
Date: January 7, 2003 at 09:38:23 Pacific
OS: linux
CPU/Ram: --
Comment:

Hi All,

I am quite new at unix script. I have two questions to ask for your help.

1) I will do quite a lot of experiments. The output file names of different experiments are different. In the post-processing script, I need to use the file names and creat directories using a part of the file name. E.g: the output filename of one experiment is rhminl85rhminh88tau5836alfa13.cam2.h1.0001-01-01-00000.nc, another one is rhminl89rhminh92tau17736alfa24.cam2.h1.0001-01-01-00000.nc. I not only need to know the names, but also want to creat directories named rhminl85rhminh88tau5836alfa13 and rhminl89rhminh92tau17736alfa24 using the same script.

2) In the script, I use qsub to submit a job. The job will run in the background. I want to execute the remaing commands in the script after the job is finished. I don't know how to succeed this.

Someone knows how to deal with these? Please do help me. Thanks for any help in advance.

Qiaozhen



Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: January 7, 2003 at 15:55:02 Pacific
Reply:

The c shell has many limitations and funny quirks - well documented. My first suggestion is that you use the korn shell, best for scripting. Even if you prefer csh for your interactive shell, the first line of your scripts can specify ksh with:

#!/bin/ksh

Your first problem is not clear to me. Do you need to process some files, but you do not know the file names? Are these files in a certain directory? If you want to process each regular file in a directory, you can have a loop like this:

for fname in `ls directory1`
do
if [ -f $fname ] ; then
print "Now processing $fname ..."
dname=${fname%%.*}
print "derived directory name is $dname"
fi

The code above also demonstrates how to pull the first part of a file name (up to the first dot) into the dname variable, and this requires korn shell. You could then create that directory, if it does not already exist, with:

if [ ! -d "$dname" ] ; then
mkdir $dname
fi

To make your script wait for the launched job to finish, I cannot help because I am not familiar with qsub. If your script were to simply run a second script, by default the second script would complete before the main script continued:

print "Now running second script ..."
./mysecondscript
print "Main continues after second script ..."

If you want the second script to run in parallel, launch with an ampersand:

print "Launching second script in parallel ..."
./mysecondscript &
print "mysecondscript now running under PID $!"


0

Response Number 2
Name: Don Arnett
Date: January 7, 2003 at 15:57:02 Pacific
Reply:

I'll take the easy one!!

For #1, it looks like the part of the filename that you want for the directory name is everything before the first period. The following command will put that part of the filename before the period into the variable DIRNAME (I'm assuming that the filename is in the variable FILENAME):

DIRNAME=`echo $FILENAME | cut -f1 -d'.'`

Note that the outermost quotes are backquotes, not normal quotes.

Use 'man cut' to look up the meaning of the parameters to 'cut'.

So, something like:

DIRNAME=`echo $FILENAME | cut -f1 -d'.'`
mkdir $DIRNAME

Would create a directory with the name extracted from the variable FILENAME



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: C shell unix script file

C Shell help www.computing.net/answers/unix/c-shell-help/5255.html

C-shell script help www.computing.net/answers/unix/cshell-script-help/6828.html

C Shell script help! www.computing.net/answers/unix/c-shell-script-help/3108.html