The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Moving files not directory. senthil_is Shell Programming and Scripting 1 05-08-2008 10:21 PM
Mutiple For loops - moving files to another directory tekster757 Shell Programming and Scripting 9 06-21-2007 05:42 AM
How to Compress files before moving them in a directory godalle Shell Programming and Scripting 3 11-10-2005 08:59 AM
moving files from a unix directory to a windows directory gleads UNIX for Dummies Questions & Answers 2 08-29-2002 05:42 PM
Suppres error message when moving files from empty source folder Steven Shell Programming and Scripting 2 11-19-2001 10:25 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-20-2007
Registered User
 

Join Date: Apr 2005
Posts: 34
Getting unusual error - moving files to another directory

Dear experts,

Im having an unusual problem and its been giving me a bad headache.
I have the script below
Code:
#!/usr/bin/sh -x

ticketinputdir=/IN_DATA1/tickets
ticketoutputdir=/IN_DATA2
YDAY=`env TZ=A12B date '+%Y%m%d'`

for i in INA INB INC IND INE
do
mkdir $ticketoutputdir/$i/$YDAY
files2mv=`ls $ticketinputdir | grep StatData$i | grep $YDAY`
chmod 777 $ticketoutputdir/$i/$YDAY
/usr/bin/mv $files2mv $ticketoutputdir/$i/$YDAY
done
I have even added the "chmod 777" command becuase i keep getting error "cannot access". I am using the "root" user to execute the scripts as well. The output of the script is something like below

Quote:
ticketoutputdir=/IN_DATA2
+ env TZ=A12B date +%Y%m%d
YDAY=20071220
+ mkdir /IN_DATA2/INA/20071220
mkdir: Failed to make directory "/IN_DATA2/INA/20071220"; File exists
+ ls /IN_DATA1/tickets
+ grep 20071220
+ grep StatDataINA
files2mv=StatDataINA_000_cat_20071220_113800.txt.Z
StatDataINA_001_cat_20071220_113800.txt.Z
StatDataINA_002_cat_20071220_113800.txt.Z
StatDataINA_003_cft_20071220_113800.txt.Z
StatDataINA_004_cft_20071220_113800.txt.Z
StatDataINA_005_cat_20071220_114800.txt.Z
StatDataINA_006_cat_20071220_114800.txt.Z
StatDataINA_007_cat_20071220_114800.txt.Z
StatDataINA_008_cat_20071220_114800.txt.Z
StatDataINA_009_cft_20071220_114800.txt.Z
StatDataINA_010_cft_20071220_114800.txt.Z
StatDataINA_011_cat_20071220_115800.txt.Z
StatDataINA_012_cat_20071220_115800.txt.Z
StatDataINA_013_cat_20071220_115800.txt.Z
StatDataINA_014_cat_20071220_115800.txt.Z
StatDataINA_015_cft_20071220_115800.txt.Z
+ chmod 777 /IN_DATA2/INA/20071220
+ /usr/bin/mv StatDataINA_000_cat_20071220_113800.txt.Z StatDataINA_001_cat_20071220_113800.txt.Z StatDataINA_002_cat_20071220_113800.txt.Z StatDataINA_003_cft_20071220_113800.txt.Z StatDataINA_004_cft_20071220_113800.txt.Z StatDataINA_005_cat_20071220_114800.txt.Z StatDataINA_006_cat_20071220_114800.txt.Z StatDataINA_007_cat_20071220_114800.txt.Z StatDataINA_008_cat_20071220_114800.txt.Z StatDataINA_009_cft_20071220_114800.txt.Z StatDataINA_010_cft_20071220_114800.txt.Z StatDataINA_011_cat_20071220_115800.txt.Z StatDataINA_012_cat_20071220_115800.txt.Z StatDataINA_013_cat_20071220_115800.txt.Z StatDataINA_014_cat_20071220_115800.txt.Z StatDataINA_015_cft_20071220_115800.txt.Z
mv: cannot access StatDataINA_000_cat_20071220_113800.txt.Z
mv: cannot access StatDataINA_001_cat_20071220_113800.txt.Z
mv: cannot access StatDataINA_002_cat_20071220_113800.txt.Z
mv: cannot access StatDataINA_003_cft_20071220_113800.txt.Z
mv: cannot access StatDataINA_004_cft_20071220_113800.txt.Z
mv: cannot access StatDataINA_005_cat_20071220_114800.txt.Z
mv: cannot access StatDataINA_006_cat_20071220_114800.txt.Z
mv: cannot access StatDataINA_007_cat_20071220_114800.txt.Z
mv: cannot access StatDataINA_008_cat_20071220_114800.txt.Z
mv: cannot access StatDataINA_009_cft_20071220_114800.txt.Z
mv: cannot access StatDataINA_010_cft_20071220_114800.txt.Z
mv: cannot access StatDataINA_011_cat_20071220_115800.txt.Z
mv: cannot access StatDataINA_012_cat_20071220_115800.txt.Z
mv: cannot access StatDataINA_013_cat_20071220_115800.txt.Z
mv: cannot access StatDataINA_014_cat_20071220_115800.txt.Z
mv: cannot access StatDataINA_015_cft_20071220_115800.txt.Z
Please help, i've been trying to crack my head. Ive even set all permissions to 777. Im using root user ID. Appreciate any help. Thanks !
Reply With Quote
Forum Sponsor
  #2  
Old 12-21-2007
andryk's Avatar
Registered User
 

Join Date: Sep 2003
Posts: 448
Hi,
how about adding another for loop instead of "mv'ing" them in one go:
Code:
#!/usr/bin/sh -x

ticketinputdir=/IN_DATA1/tickets
ticketoutputdir=/IN_DATA2
YDAY=`env TZ=A12B date '+%Y%m%d'`

for i in INA INB INC IND INE
do
    mkdir -p $ticketoutputdir/$i/$YDAY
    files2mv=`ls $ticketinputdir | grep StatData$i | grep $YDAY`
    for j in $files2mv
    do
        mv $j $ticketoutputdir/$i/$YDAY && echo $j moved to $ticketoutputdir/$i/$YDAY
    done
done
Reply With Quote
  #3  
Old 12-21-2007
Registered User
 

Join Date: Apr 2005
Posts: 34
Hi andryk,

I tried the method you adviced above. I'm still getting the following errors. Ivae changed all permissions to 777. This is really wierd.

Quote:
+ mv StatDataINE_884_cat_20071220_115800.txt.Z /IN_DATA2/INE/20071220
mv: cannot access StatDataINE_884_cat_20071220_115800.txt.Z
+ mv StatDataINE_885_cat_20071220_115800.txt.Z /IN_DATA2/INE/20071220
mv: cannot access StatDataINE_885_cat_20071220_115800.txt.Z
+ mv StatDataINE_886_cat_20071220_115800.txt.Z /IN_DATA2/INE/20071220
mv: cannot access StatDataINE_886_cat_20071220_115800.txt.Z
+ mv StatDataINE_887_cft_20071220_115800.txt.Z /IN_DATA2/INE/20071220
mv: cannot access StatDataINE_887_cft_20071220_115800.txt.Z
+ mv StatDataINE_888_cat_20071220_120900.txt.Z /IN_DATA2/INE/20071220
mv: cannot access StatDataINE_888_cat_20071220_120900.txt.Z
+ mv StatDataINE_889_cat_20071220_120900.txt.Z /IN_DATA2/INE/20071220
mv: cannot access StatDataINE_889_cat_20071220_120900.txt.Z
+ mv StatDataINE_890_cat_20071220_120900.txt.Z /IN_DATA2/INE/20071220
mv: cannot access StatDataINE_890_cat_20071220_120900.txt.Z
+ mv StatDataINE_891_cat_20071220_120900.txt.Z /IN_DATA2/INE/20071220
mv: cannot access StatDataINE_891_cat_20071220_120900.txt.Z
+ mv StatDataINE_892_cft_20071220_120900.txt.Z /IN_DATA2/INE/20071220
mv: cannot access StatDataINE_892_cft_20071220_120900.txt.Z
+ mv StatDataINE_893_cft_20071220_120900.txt.Z /IN_DATA2/INE/20071220
mv: cannot access StatDataINE_893_cft_20071220_120900.txt.Z
+ mv StatDataINE_894_cat_20071220_121800.txt.Z /IN_DATA2/INE/20071220
mv: cannot access StatDataINE_894_cat_20071220_121800.txt.Z
+ mv StatDataINE_895_cat_20071220_121800.txt.Z /IN_DATA2/INE/20071220
Reply With Quote
  #4  
Old 12-21-2007
Registered User
 

Join Date: Apr 2005
Posts: 34
andryk, i fugured out the problem. its because when the second loop takes place, it cannot understand the full path of StatDataINE_890_cat_20071220_120900.txt.Z. Ive modified the script. Thanks !!!
Reply With Quote
  #5  
Old 12-21-2007
andryk's Avatar
Registered User
 

Join Date: Sep 2003
Posts: 448
I did not see the 'trap' too, the correct version is
Code:
#!/usr/bin/sh -x

ticketinputdir=/IN_DATA1/tickets
ticketoutputdir=/IN_DATA2
YDAY=`env TZ=A12B date '+%Y%m%d'`

for i in INA INB INC IND INE
do
    mkdir -p $ticketoutputdir/$i/$YDAY
    files2mv=`ls $ticketinputdir | grep StatData$i | grep $YDAY`
    for j in $files2mv
    do
        mv $ticketinputdir/$j $ticketoutputdir/$i/$YDAY && echo $j moved to $ticketoutputdir/$i/$YDAY
    done
done
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0