Solved

process csh line by line items properly

Posted on 2006-11-19
6
250 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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 …
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…

809 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