Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

cannot stat error

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 07-15-2010
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 2 December 2016, 12:57 PM EST
Location: Foxborough, MA
Posts: 7,988
Thanks: 194
Thanked 698 Times in 654 Posts

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

Sponsored Links
    #3  
Old Unix and Linux 07-15-2010
radoulov's Unix or Linux Image
radoulov radoulov is offline Forum Advisor  
Forum Adviser
 
Join Date: Jan 2007
Last Activity: 16 December 2015, 5:59 AM EST
Location: Варна, България / Milano, Italia
Posts: 5,690
Thanks: 184
Thanked 629 Times in 586 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 Unix and Linux 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 Unix and Linux 07-15-2010
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 30 November 2016, 10:00 AM EST
Location: NM
Posts: 10,874
Thanks: 457
Thanked 984 Times in 915 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 Unix and Linux 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 Linux
Sponsored Links
    #7  
Old Unix and Linux 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 Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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
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:49 PM.