The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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-09-2008 01:21 AM
Mutiple For loops - moving files to another directory tekster757 Shell Programming and Scripting 9 06-21-2007 08:42 AM
How to Compress files before moving them in a directory godalle Shell Programming and Scripting 3 11-10-2005 11:59 AM
moving files from a unix directory to a windows directory gleads UNIX for Dummies Questions & Answers 2 08-29-2002 08:42 PM
Suppres error message when moving files from empty source folder Steven Shell Programming and Scripting 2 11-19-2001 01:25 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-21-2007
aismann aismann is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 37
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 !
  #2 (permalink)  
Old 12-21-2007
andryk's Avatar
andryk andryk is offline Forum Advisor  
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
  #3 (permalink)  
Old 12-21-2007
aismann aismann is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 37
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
  #4 (permalink)  
Old 12-21-2007
aismann aismann is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 37
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 !!!
  #5 (permalink)  
Old 12-21-2007
andryk's Avatar
andryk andryk is offline Forum Advisor  
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0