Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

process csh line by line items properly

Posted on 2006-11-19
6
Medium Priority
?
258 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 3

Accepted Solution

by:
nishayr earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

704 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