Archiving the files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Archiving the files
# 1  
Old 06-03-2013
Archiving the files

hi,

Am trying to acrhive a bunch of files on some ftp site and somehow managed to come out with the below logic.
I'm getting "syntax error: unexpected end of file" error. Interestingly this below snipeet works fine if run for the first time but the subsequent runs fail!
Anybody has any idea why it's behaving so weird??

Code:
#!/bin/bash -x
. $HOME/bin/env.sh
export HOST=some@site.com
export USER=abc
export PASS=xyz
export FILEPATH=$HOME/bin
rm -f $FILEPATH/temp
cd $HOME/download
ftp -i -v -n $HOST <<EOF > $HOME/get.log
        user $USER $PASS
        mget *.csv
        disconnect
        bye
EOF
cd $HOME/download
ls -lrt | tr -s " " | cut -d " " -f9 | grep -v ^$ > $FILEPATH/temp
if [ -s $FILEPATH/temp ];then
        while read line
        do
                echo "rename /$line /archive/$line.processed"
        done < $FILEPATH/temp > $FILEPATH/query
        while read line
        do
                ftp -in $HOST <<EOF > $HOME/archive.log
                user $USER $PASS
                $line
                disconnect
                bye
                EOF
        done < $FILEPATH/query
fi
rm -f $FILEPATH/query
exit;


Last edited by Amee5; 06-03-2013 at 12:02 PM.. Reason: Please use code tags
# 2  
Old 06-04-2013
Take the semi-colon off the end of the 'exit;' and try it or remove the 'exit;' statement since your not exiting with a return code.
If you were to check the status code($?) after the script runs it would be for the last command run(i.e. rm).
# 3  
Old 06-04-2013
Quote:
Originally Posted by Amee5
hi,

Am trying to acrhive a bunch of files on some ftp site and somehow managed to come out with the below logic.
I'm getting "syntax error: unexpected end of file" error. Interestingly this below snipeet works fine if run for the first time but the subsequent runs fail!
Anybody has any idea why it's behaving so weird??

Code:
#!/bin/bash -x
. $HOME/bin/env.sh
export HOST=some@site.com
export USER=abc
export PASS=xyz
export FILEPATH=$HOME/bin
rm -f $FILEPATH/temp
cd $HOME/download
ftp -i -v -n $HOST <<EOF > $HOME/get.log
        user $USER $PASS
        mget *.csv
        disconnect
        bye
EOF
cd $HOME/download
ls -lrt | tr -s " " | cut -d " " -f9 | grep -v ^$ > $FILEPATH/temp
if [ -s $FILEPATH/temp ];then
        while read line
        do
                echo "rename /$line /archive/$line.processed"
        done < $FILEPATH/temp > $FILEPATH/query
        while read line
        do
                ftp -in $HOST <<EOF > $HOME/archive.log
                user $USER $PASS
                $line
                disconnect
                bye
                EOF
        done < $FILEPATH/query
fi
rm -f $FILEPATH/query
exit;

In your first here-document, you had the closing word at the start of the line (and it worked). In your second here-document (marked in red above), the line that you intend to be the end of the here-document is indented, so it is not recognized. Either get rid of the whitespace before the EOF or change the <<EOF to <<-EOF.
This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 06-04-2013
hi Don,

Removing the white space before EOF indeed worked!

Thanks buddy! Thanks everyone..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Archiving files using shell script

Dear Team, I am looking for transferring files to and from the local and remote servers using SFTP commands. Currently the script is using the mget and mput commands to do the copying of the files. While I am trying to move the files from local to remote server, I would also like to archive... (21 Replies)
Discussion started by: Rads
21 Replies

2. Shell Programming and Scripting

Archiving older files

Hello Group, I would request your help to build a shell script in order to find files older than 90 days then create the same directory structure under the second disk (/archive directory) and move the file preserving the same timestamps (ownership, etc). Also keep the log of files moved... (4 Replies)
Discussion started by: csierra
4 Replies

3. UNIX for Dummies Questions & Answers

Archiving the files in a .txt file

HI , I have a file abc.txt, which has some .csv files listed. example. abc.txt 1.csv 2.csv 3.csv 4.csv 5.csv I want to move all the files listed in abc.txt to a archive directory,and zip the moved files. Can anyone help me with the script. Thanks,sai (1 Reply)
Discussion started by: saii
1 Replies

4. Shell Programming and Scripting

Issue while archiving the files

Hi, In our current process we are reading the file, (which is placed by external vendor)from one particular folder and processing those files through ETL(informatica). We are reading these file as " ls -ltr *.txt" Once the process is finish these files are moved to archived script by "mv"... (1 Reply)
Discussion started by: Amey Joshi
1 Replies

5. Shell Programming and Scripting

Archiving the Files in a folder

My requirement is to put all the files from output directory(ATT) to archive directory(archive\) creating a new folder with datetimestamp(20100212_120014) every time it runs. where ${IMF_TARGET_DIR} is my base directory. ${IMF_ARCHIVE_DIR} is my Archive directory... (1 Reply)
Discussion started by: vsmeruga
1 Replies

6. UNIX for Dummies Questions & Answers

Archiving and move files in the same time

Hi All, I have tried so many command but none work like i wanted. I would like archive which i assume it will move the files and archive it somewhere. for example: if i have a folder and files: /home/blah/test /home/blah/hello /home/blah/foo/bar i would like to archive folder... (6 Replies)
Discussion started by: c00kie88
6 Replies

7. Shell Programming and Scripting

Archiving the files

Hi, Suppose I have 2 files of yesterday's. And today I have received 3 files. Before processing anything I want to archieve the 2 files of yesterday's into a different folder. How can this be done? Regards, Sunitha (1 Reply)
Discussion started by: Sunitha_edi82
1 Replies

8. UNIX for Dummies Questions & Answers

Archiving big ammount of files.

Hello All. I have problem archiving files. The problem is:) I have about 10000 files in one directory, all this file aproximately the same size, i need to gzip them and write on DVD. But all this files take about 15 GB of space (already gzipped). So i need DVD Blue-Ray :p or i need to split... (3 Replies)
Discussion started by: Maxeg
3 Replies

9. Shell Programming and Scripting

Archiving and moving the files

hi all i have a requirement where in i have to zip all the files with "*.bkp" after 14 days and move the zip files to Archive directory .... i am able to achieve the first functionality but not able to achive the second one ...here is my code find ${LOG_DIR} -name "*.bkp" -mtime +14 | xargs -i... (1 Reply)
Discussion started by: nvuradi
1 Replies

10. UNIX for Dummies Questions & Answers

Backing up or Archiving files in UNIX

Hi All, I am very new to the UNIX world and find myself in a new position at work that requires me to archive large CADD files based in both UNIX and Windows environments on CD's. I have one engineer that wants to export these files as a table (I guess) and it appears to have a lot of paper... (2 Replies)
Discussion started by: Dsartelle
2 Replies
Login or Register to Ask a Question