shell script help needed to manage FTP automation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script help needed to manage FTP automation
# 1  
Old 09-18-2012
Question shell script help needed to manage FTP automation

Hi,
I am very new in shell scripting. Have managed to prepare a script which will work to download data to local directory. But facing below problem. Smilie

Please help me out. Thanks in advance.

Problem:
1. I am unable to use delete command to delete data in the ftp location (I have permission to delete).

2. I don't want to download or delete data which are under precessing, file will have .curr extention.

complete file name sample: icdr.5_8_2A.0.1.201209131146.000014.0
complete file name sample: icdr.5_8_2A.0.1.201209131146.000014.curr

naming convention: icdr.version_number.zone_id.cdr_id.timestamp.sequence.new_sequence_indicator

my script:

Code:
#!/usr/bin/ksh
# CDR file location
SRC_1="/u01/raw/testcdr/"
#Credential

ipadd="myIPaddress"
user="userid"
pass="password"
remotedir="/cdr/ICDR/primary/"
pref="icd*"
TEMP_LIST_FILE="tempfilecheck_CDR"
FTPFLAGS="-n"


ftpresult1=`ftp $FTPFLAGS $ipadd <<EOF
    user $user $pass
    bin
    prompt
    cd $remotedir
    nlist $pref $TEMP_LIST_FILE
    bye
    EOF`


for i in `cat $TEMP_LIST_FILE`;do
        ftpresult2=`ftp $FTPFLAGS $ipadd <<EOF
        user $user $pass
        bin
        prompt
        cd $remotedir
        lcd $SRC_1
        mget $i
        bye
        EOF`
done


Last edited by Corona688; 09-18-2012 at 05:25 PM..
# 2  
Old 09-18-2012
Does your system have ssh or scp available? ftp is extremely hard to automate.

Quote:
Originally Posted by ImranBD
1. I am unable to use delete command to delete data in the ftp location (I have permission to delete).
I don't see your script deleting anything. What are you trying to delete, how do you try to delete it, and in what way does it not work?
Quote:
2. I don't want to download or delete data which are under precessing, file will have .curr extention.
Please explain your script further. I'm not entirely clear on what your first step does. Please show what ends up in your $TEMP_LIST_FILE.

Your second step is a pointless and dangerous use of backticks.

I also suspect you don't need to run ftp 5,000 times to download 5,000 files.

Why are you putting the second ftp in backticks if you never use the result?

I don't think you need mget to download individual files.

Your here-documents will not work, because the ending EOF must be at the beginning of the line, not indented.
# 3  
Old 09-18-2012
Maybe something like this?

Code:
ftp $FTPFLAGS $ipadd <<EOF
    user $user $pass
    bin
    prompt
    cd $remotedir
    nlist $pref $TEMP_LIST_FILE
    bye
EOF


cat <<EOF > /tmp/$$
    user $user $pass
    bin
    prompt
    cd $remotedir
EOF

awk '!/[.]curr$/ { print "get " $0 } END { print "bye" }' $TEMP_LIST_FILE >> /tmp/$$

ftp $FTPFLAGS $ipadd < /tmp/$$

rm -f /tmp/$$ $TEMP_LIST_FILE

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

FTP a file using Shell Scripting (Help needed)

the requirements is to have a linux script which connects to a windows machine using ftp command and check for a flag file if found copy a .csv file into current machine. (3 Replies)
Discussion started by: tradingspecial
3 Replies

2. Shell Programming and Scripting

Help with Truststore automation shell script

Please close this thread. I have raise this question in appropriate thread. Thanks (0 Replies)
Discussion started by: KuldeepSinghTCS
0 Replies

3. Shell Programming and Scripting

Help with Shell Script automation

can someone look into this one please... I am struck at this point. I do not know what logic to be followed here. I can go ahead with my work only, if this step is done. Please Help. I have a process X in a shell script. Once the process X is done, it generates a log file. Process X is basically... (1 Reply)
Discussion started by: ss3944
1 Replies

4. Shell Programming and Scripting

FTP automation script

Hi, I have got a requirement like this. a parameterized function custFtp which will take 5 i/ps and will do the following tasks. p1) server name p2) username p3) password p4) path name of the server where the file resides p5) file name pattern the function will work like this. ... (1 Reply)
Discussion started by: ani_datta
1 Replies

5. Shell Programming and Scripting

Manage starting point in shell script.

Hi, I'd like to run a script with an optional starting point. Meaning that if no parameter for the script => Do everything, otherwise start from the point specified in the parameter and continue till the end. I thought of using the "case ..." but I have no result. Script: # ---------------... (6 Replies)
Discussion started by: ai_dba
6 Replies

6. Filesystems, Disks and Memory

Urgent FTP script automation

Hi guys, Here is my requirement for ftp script that i have to automate in unix using shell script: 1) Find the files that atre created one week from the present day. 2) ftp them to the backup server. 3) At the end of the month make a new directory on my backup server with the new month(eg:Once... (1 Reply)
Discussion started by: koduri0475
1 Replies

7. UNIX Desktop Questions & Answers

Urgent FTP script automation

Hi guys, Here is my requirement for ftp script that i have to automate in unix using shell script: 1) Find the files that atre created one week from the present day. 2) ftp them to the backup server. 3) At the end of the month make a new directory on my backup server with the new month(eg:Once... (1 Reply)
Discussion started by: koduri0475
1 Replies

8. UNIX for Dummies Questions & Answers

Urgent FTP script automation

Hi guys, Here is my requirement for ftp script that i have to automate in unix using shell script: 1) Find the files that atre created one week from the present day. 2) ftp them to the backup server. 3) At the end of the month make a new directory on my backup server with the new month(eg:Once... (1 Reply)
Discussion started by: koduri0475
1 Replies

9. Shell Programming and Scripting

How to manage multiple versions of a set of shell and SQL script utilities

Hi all --- I have the need to manage multiple versions of a set of utility scripts -- both shell and SQL and other .dat files. I am wondering if anyone out there knows of a good way to "PATH" to SQL and text files in a way similar to how PATH facilitates finding executables in a pre-specified... (2 Replies)
Discussion started by: DennisB
2 Replies

10. Shell Programming and Scripting

Shell script automation using case statement

Hi, I'm trying to write a shell script that has a menu and then dependant on the selection, will automate some samba file transfer. The problem is when I run the code without the case statement it runs fine. but when I put the case statement in the only way I can get the code to run is to... (6 Replies)
Discussion started by: ianf
6 Replies
Login or Register to Ask a Question