Solved

process csh line by line items properly

Posted on 2006-11-19
6
248 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
  • 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
This is an explanation of a simple data model to help parse a JSON feed
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now