Solved

process csh line by line items properly

Posted on 2006-11-19
6
253 Views
Last Modified: 2008-02-01
Hi

I have a csh script that reads files names line by line and acts on each file name (for eg:recursive chmod  -R  or some sort of conversion on the file eg: change its data format type from iff to some other etc)
I find that sometimes if it takes a long time to chmod a particular file, and if the script has already read in the next filename then it breaks the previous action on the previous file, and goes on to the newly read file. In other words, some previous pipe is broken.

IS there some way to spawn each action on each file as it is read separately?

What exactly is going on here? Why does the previous action on the file break if it takes a long time to complete?


0
Comment
Question by:LuckyLucks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 17974944
are you trying to do the chmod in background?
how and why are you reading the next filename before the chmod is finished?
0
 
LVL 3

Expert Comment

by:nishayr
ID: 17976410
Hi there,

*nix usually has a find command. This command is extremely useful for doing what I think you are trying to do.

for example:

find . -name '*.html' -exec chmod 664 {} \;

would find all the files with a .html extension in the curernt directory, and for each file it locates it will run the command between the '-exec' and the '\;' it. The '{}' is replaced by each file in turn...

Explanation and examples of find: http://www.devdaily.com/unix/edu/examples/find.shtml

Thanks,
Nish
0
 

Author Comment

by:LuckyLucks
ID: 17976458
Hi

I gave chmod as an example of some action that is executed on a file. It does not necessarily have to be a chmod. It can be any process that is rather lengthy in nature like conversion of one file type to another.
I know about the find command but I rather not use it in this example because the action on the filename can be more complicated than executing one command on the filename. for example i may want to read the filename , rename some parts of the filename, convert the filetype and write it out to a different directory.
If i used the find command, it may get  very complicated to write it properly.

I am basically interested in knowing what happens when one executes lengthy actions on a file but the next file name in read by then.

eg: of script
#!/usr/bin/csh

<lengthy action command> file1
<lengthy action command> file2
<lengthy action command> file3
<lengthy action command> file4
:
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
nishayr earned 500 total points
ID: 17976896
Hey again,

#!/usr/bin/csh

<lengthy action command> file1

Script should stop here until above command completes either successfully or unsuccessfully.
If you want the script to not stop here but continue processing the below commands while still working on the above command, then you append a '&' to the line which forks off a new process to handle that commend.
(e.g. <lengthy action command> file1 & )

<lengthy action command> file2
<lengthy action command> file3
<lengthy action command> file4


So to answer your question, the 2nd command should not start executing until the first command has completed...



Thanks,
Nish
0
 

Author Comment

by:LuckyLucks
ID: 17980305
"So to answer your question, the 2nd command should not start executing until the first command has completed..."


On the contrary, it seems like it is doing the next line ....Otherwise, why would there be broken pipes from the previous line when it tried to do an action on the  previous file.
0
 
LVL 3

Expert Comment

by:nishayr
ID: 17984251
Does the <lengthy action command> involve forking or background processing?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question