cannot stat error | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

cannot stat error

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-15-2010
rss0213 rss0213 is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 18 May 2011, 9:45 PM EDT
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
cannot stat error

I'm trying to find .tif files in a directory tree and rename them prior to zipping them and moving them to another dir. this is my code:


Code:
   cd $TMPPATH
   pwd
   ctr=0
   for i in 'find . -name "*.tif"'
   do
      let "ctr+=1"
      newtifname=$DATEDIR"_"$SEQ"_"$ctr".tif"
      mv "$i" "$newtifname" | zip -j $output_zip_file -@ >> $LOG
   done

When I execute this, I get the following error:

Quote:
/tmp/image/LKOFAX/04
mv: cannot stat `find . -name "*.tif"': No such file or directory
But when I cd to this directory (outside my script) and execute the same find command, I see a *.tif images.

Quote:
[apache@fpu0a corr]$ cd /tmp/image/LKOFAX/04
[apache@fpu0a 04]$ find . -name "*.tif"
./245678/20100709/outputs/i4/corr/1.tif
Anyone see what I'm doing wrong?
Sponsored Links
    #2  
Old 07-15-2010
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 21 November 2014, 1:36 PM EST
Location: Foxborough, MA
Posts: 7,668
Thanks: 153
Thanked 586 Times in 551 Posts

Code:
for i in `find . -name "*.tif"`

Sponsored Links
    #3  
Old 07-15-2010
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 21 November 2014, 5:01 AM EST
Location: Варна, България / Milano, Italia
Posts: 5,675
Thanks: 184
Thanked 620 Times in 578 Posts
Yes,
it appears that you want a command substitution in the for loop list of items:


Code:
$(find . -name "*.tif")

This is not the right way to do such a thing though, if any of the file names found contains white spaces or other pathological characters your script will fail.

This should be better implemented with a while loop, modifying the current IFS.
The Following User Says Thank You to radoulov For This Useful Post:
rss0213 (07-15-2010)
    #4  
Old 07-15-2010
rss0213 rss0213 is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 18 May 2011, 9:45 PM EDT
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
So just remove single quotes? I tried this, and got this result:

Quote:
/tmp/image/LKOFAX/04
mv: cannot stat `find': No such file or directory

zip error: Nothing to do! (LKOFAX_04_20100709.zip)
mv: cannot move `.' to `20100709_04_2.tif': Device or resource busy

zip error: Nothing to do! (LKOFAX_04_20100709.zip)
mv: invalid option -- n
Try `mv --help' for more information.

zip error: Nothing to do! (LKOFAX_04_20100709.zip)
mv: cannot stat `*.tif': No such file or directory

zip error: Nothing to do! (LKOFAX_04_20100709.zip)
Sponsored Links
    #5  
Old 07-15-2010
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 21 November 2014, 12:22 PM EST
Location: NM
Posts: 10,278
Thanks: 287
Thanked 814 Times in 756 Posts
NO. You need a child process for find that the parent waits for:

Code:
for i in $find . -name "*.tif" )

backtics ` ` or the $( ) construct mean the same thing. You just found out why the backtic thing has problems - it is hard to see and easy to mess up. I used the $( ) thing because it is hard to mistake for something else.
The Following User Says Thank You to jim mcnamara For This Useful Post:
rss0213 (07-15-2010)
Sponsored Links
    #6  
Old 07-15-2010
dr.house dr.house is offline
Registered User
 
Join Date: Dec 2008
Last Activity: 30 October 2011, 12:05 PM EDT
Location: Switzerland
Posts: 454
Thanks: 4
Thanked 27 Times in 27 Posts
Quote:
Originally Posted by rss0213 View Post

Code:
for i in 'find . -name "*.tif"'

These backticks look like ordinary quotes to me
Sponsored Links
    #7  
Old 07-15-2010
rss0213 rss0213 is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 18 May 2011, 9:45 PM EDT
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Thank you radoulov and jim (for the explanation). It's working now.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to resolve error "INIT: Cannot stat /etc/inittab, errno: 2" surbhit4u Solaris 14 05-24-2010 08:03 AM
what is a "find stat() error" orahi001 UNIX for Dummies Questions & Answers 2 05-07-2009 06:32 PM
stat command error!! G.K.K Shell Programming and Scripting 5 10-06-2008 09:39 AM
Cannot Stat Error Homer Allman UNIX for Advanced & Expert Users 1 05-22-2006 11:07 AM
sort can't stat error. radhika Shell Programming and Scripting 5 06-03-2005 12:34 AM



All times are GMT -4. The time now is 03:05 PM.