Solved

process csh line by line items properly

Posted on 2006-11-19
6
254 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
Independent Software Vendors: 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is about my first experience with programming Arduino.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Starting up a Project

734 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