Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

cannot stat error

Shell Programming and Scripting


Closed Linux or Unix Question    
 
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 online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 8 July 2015, 2:27 AM EDT
Location: Foxborough, MA
Posts: 7,825
Thanks: 174
Thanked 653 Times in 610 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 Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 23 April 2015, 3:05 PM EDT
Location: Варна, България / Milano, Italia
Posts: 5,690
Thanks: 184
Thanked 625 Times in 583 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: 7 July 2015, 7:29 PM EDT
Location: NM
Posts: 10,497
Thanks: 344
Thanked 869 Times in 807 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 Linux or Unix Question

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 07:03 AM
what is a "find stat() error" orahi001 UNIX for Dummies Questions & Answers 2 05-07-2009 05:32 PM
stat command error!! G.K.K Shell Programming and Scripting 5 10-06-2008 08:39 AM
Cannot Stat Error Homer Allman UNIX for Advanced & Expert Users 1 05-22-2006 10:07 AM
sort can't stat error. radhika Shell Programming and Scripting 5 06-02-2005 11:34 PM



All times are GMT -4. The time now is 02:33 AM.