Computing.Net > Forums > Unix > Tansfer files script to be modified

Tansfer files script to be modified

Reply to Message Icon

Original Message
Name: naelaladimi
Date: March 27, 2004 at 06:16:35 Pacific
Subject: Tansfer files script to be modified
OS: Solaris 8
CPU/Ram: SPARC/6144MB
Comment:

here i have a transfer script that draws files by date but now we have to add time in the files format according to the generation time of those files and that made it difficult to modify the script...

could you please suggest and see whats the prob in it....

i want the script to automatically understand the files that get generated in different timings a day and knows whats the next file should be gotten.

here is the script:

REP=/u05/home/Nael
#read a < $REP/last_file
read a < $REP/najib/naeltestCDR
echo $a
y=`echo $a | cut -c17-20`
m=`echo $a | cut -c21-22`
d=`echo $a | cut -c23-24`
H=`echo $a | cut -c26-27`
M=`echo $a | cut -c28-29`
S=`echo $a | cut -c30-31`

y_next=$y
m_next=$m
d_next=$d
H_next=$H
M_next=$M
S_next=$S

if [ $d -eq 31 ] || ( [ $d -eq 30 ] && ( [ $m -eq 04 ] || [ $m -eq 06 ] || [ $m -eq 09 ] || [ $m -eq 11 ] ) )
then
d_next=01
if [ $m -eq 12 ]
then
m_next=01
y_next=`expr $y + 1`
else
m_next=`expr $m + 1`
if [ $m_next -le 9 ]
then
m_next=0$m_next
fi
fi
else
if [ $d -eq 28 ] && [ $m -eq 2 ]
then
d_next=01
m_next=03
else
d_next=`expr $d + 1`
if [ $d_next -le 9 ]
then
d_next=0$d_next
fi
fi
fi
next_file=VXT_CDR_305_333_$y_next$m_next$d_next_$H_next$M_next$S_next.DAT
echo $next_file


> $REP/.netrc
chmod 600 $REP/.netrc
echo "machine jinny" >> $REP/.netrc
echo "login username" >> $REP/.netrc
echo "password passwd" >> $REP/.netrc

echo "macdef init" >> $REP/.netrc
echo " binary" >> $REP/.netrc
echo " prompt off" >> $REP/.netrc
echo " lcd /u05/home/Nael/najib/Jinny" >> $REP/.netrc
echo " cd vxt" >> $REP/.netrc
echo " mget $next_file" >> $REP/.netrc
echo " quit\n" >> $REP/.netrc
ftp jinny > ftp_305.log
ls /u05/home/Nael/najib/Jinny > /u05/home/Nael/najib/Jinny/list_305.log
if grep $next_file /u05/home/Nael/najib/Jinny/list_305.log > /dev/null
#if [ $? -eq 1 ]
then
echo $next_file > /u05/home/Nael/najib/last_jinny_305
chmod 774 /u05/home/Nael/najib/Jinny/$next_file
echo $next_file >> ftp_305.log
echo " Transfer is Successful" >> ftp_0.log
fi
exit

Thank you very much for your cooperation....


Report Offensive Message For Removal


Response Number 1
Name: aigles
Date: March 27, 2004 at 13:56:58 Pacific
Subject: Tansfer files script to be modified
Reply: (edit)

List the remote directory to determine the next file to get.

For example :
last_file = VXT_CDR_305_333_20040327_080000.DAT

List of the remote directory sorted by name :
VXT_CDR_305_333_20040326_120000.DAT
VXT_CDR_305_333_20040327_080000.DAT <- last file
VXT_CDR_305_333_20040327_120000.DAT <- next file

You can do something like this (!!! NOT TESTED !!!)


#
# GetNextFileName - Get the name of the next file to get
# The next file to get is the first file in the remote directory
# with a name greater than the name of the last file.
#

GetNextFileName() {
   root_file=`echo "$last_file" | sed 's/_[0-9]*_[0-9]*\..*$//'`
   cat <<-EOD_CAT >$REP/.netrc
        machine jinny
        login username
        password password
        macdef init
         binary
         prompt off
         lcd /u05/home/Nael/najib/Jinny
         ls
         quit
        
        EOD_CAT
   chmod 600 $REP/.netrc
   ftp jinny | grep "^$root_file" | sort > /tmp/ftp_305_files.log
   next_file=`awk '$0 > Last {print ; exit}' Last=$last_file /tmp/ftp_305_files.log`
}

#
# GetNexFile - Get the next file
#

GetNextFile() {
   cat <<-EOD_CAT >$REP/.netrc
        machine jinny
        login username
        password password
        macdef init
         binary
         prompt off
         lcd /u05/home/Nael/najib/Jinny
         cd vxt
         mget $next_file
         quit
        
        EOD_CAT
   chmod 600 $REP/.netrc
   ftp jinny > ftp_305.log
   ls /u05/home/Nael/najib/Jinny > /u05/home/Nael/najib/Jinny/list_305.log
   grep -q $next_file /u05/home/Nael/najib/Jinny/list_305.log
}

#
# M A I N . . .
#

last_file_memo=/u05/home/Nael/najib/last_jinny_305
read last_file filler < $last_file_memo
next_file=`GetNextFileName`

if [ -n "$next_file" ] ; then
   if GetNextFile ; then
      echo $next_file > $last_file_memo
      chmod 774 /u05/home/Nael/najib/Jinny/$next_file
      echo $next_file >> ftp_305.log
      echo " Transfer is Successful" >> ftp_0.log
   fi
fi

Jean-Pierre.



Report Offensive Follow Up For Removal

Response Number 2
Name: naelaladimi
Date: March 27, 2004 at 23:02:21 Pacific
Subject: Tansfer files script to be modified
Reply: (edit)

Thank you very much for the cooperation but it doesnt really read the file correctly... what i meant is it doesnt calculate or see the minutes as it searches for the next file in the next date not in the same day though we have many files get generated a day.... how to make it hold in the same day...???????


Report Offensive Follow Up For Removal

Response Number 3
Name: aigles
Date: March 28, 2004 at 08:54:31 Pacific
Subject: Tansfer files script to be modified
Reply: (edit)

When you execute your script which files do you want to get ?

All the generated files not yet transfered ?
My example script can be modified to transfert not only the first file but all files.

All the files not yet transfered for the next day of the last file transfered ?
- compute next_date
- get list of file to be transfered, their name is in the form : VXT_CDR_305_333_${next_date}_*.DAT
- for every file found, transfert the file.

Jean-Pierre.


Report Offensive Follow Up For Removal

Response Number 4
Name: naelaladimi
Date: March 29, 2004 at 00:38:47 Pacific
Subject: Tansfer files script to be modified
Reply: (edit)

it throws out this error
syntax error at line 3 : `<<' unmatched
because of this line cat <<-EOD_CAT >$REP/.netrc


Report Offensive Follow Up For Removal

Response Number 5
Name: aigles
Date: March 29, 2004 at 01:35:25 Pacific
Subject: Tansfer files script to be modified
Reply: (edit)

lines between '<<-EOD_CAT' and EOD_CAT start with a tabulation.

Jean-Pierre.


Report Offensive Follow Up For Removal


Response Number 6
Name: naelaladimi
Date: March 29, 2004 at 02:39:13 Pacific
Subject: Tansfer files script to be modified
Reply: (edit)

sorry but it has thrown those errors ....

computing1[2]: /.netrc: cannot create
computing1[6]: macdef: not found
computing1[7]: binary: not found
computing1[8]: prompt: not found
computing1[9]: lcd: not found
computing1[11]: quit: not found
computing1[13]: EOD_CAT: not found
chmod: WARNING: can't access /.netrc
computing1: /.netrc: cannot create
machine jinny
login ftponly
password ftp123
computing1[5]: macdef: not found
computing1[6]: binary: not found
computing1[7]: prompt: not found
computing1[8]: lcd: not found
computing1[9]: vxt: not found
computing1[10]: mget: not found
computing1[11]: quit: not found
computing1[13]: EOD_CAT: not found
chmod: WARNING: can't access /.netrc
grep: illegal option -- q
Usage: grep -hblcnsviw pattern file . . .


Report Offensive Follow Up For Removal

Response Number 7
Name: aigles
Date: March 29, 2004 at 05:10:10 Pacific
Subject: Tansfer files script to be modified
Reply: (edit)

I forgot the assignment of REP
Add before last_file_memo assignment :

REP=/u05/home/Nael


Seems that your grep command doesnt support the -q option.
Change

grep -q $next_file /u05/home/Nael/najib/Jinny/list_305.log

by

grep $next_file /u05/home/Nael/najib/Jinny/list_305.log > /dev/null

Jean-Pierre.


Report Offensive Follow Up For Removal

Response Number 8
Name: naelaladimi
Date: March 29, 2004 at 08:00:51 Pacific
Subject: Tansfer files script to be modified
Reply: (edit)

i really appreciate your concern bud...
but you know something... now its not giving any error but it hangs .. and i meant by hang, it shows that its processing something but its not as its not going out to the prompt...

execuse me, should i add something from my script to yours or only your script alone should be followed?

Thanks anyway man....


Report Offensive Follow Up For Removal

Response Number 9
Name: aigles
Date: March 29, 2004 at 09:24:46 Pacific
Subject: Tansfer files script to be modified
Reply: (edit)

You can execute the script aloane, but remember it is NOT TESTED.

Add a 'set -x' statement for debuging at the beginning of the script and of the two functions (GetNextFileName, GetNextFile).

Execute the script and analyze the executed commands.

Jean-Pierre.


Report Offensive Follow Up For Removal

Response Number 10
Name: naelaladimi
Date: March 29, 2004 at 22:34:44 Pacific
Subject: Tansfer files script to be modified
Reply: (edit)

this is the result...

+ REP=/u05/home/Nael
+last_file_memo=/u05/home/Nael/najib/last_jinny_305
+ read last_file
+ 0< /u05/home/Nael/najib/last_jinny_305
+ + GetNextFileName


and then it hangs...


Report Offensive Follow Up For Removal

Response Number 11
Name: aigles
Date: March 31, 2004 at 06:56:32 Pacific
Subject: Tansfer files script to be modified
Reply: (edit)

Add 'set -x' in the GetNextFileName function

Verify the generated .netrc file (delete file if exists before executing your script)

Verify the contents of the resulting file /tmp/ftp_305_files.log

Jean-Pierre.


Report Offensive Follow Up For Removal

Response Number 12
Name: naelaladimi
Date: April 2, 2004 at 05:21:49 Pacific
Subject: Tansfer files script to be modified
Reply: (edit)

correct me if im wrong, i guess that the last_file variable should be defined in order for the script to understand what is it....

if that is true... how did you want it to be defined???

thanks....


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Tansfer files script to be modified

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge