Cron Jobs for FTP download

Dear All,

Please to be inform you,I have posted one thread on this forum last 5 days back. I was not getting suggestions for my thread. So i am creating a new thread with detailed of my R&D.

I am new in Shell Scripts, Perl and Cron Jobs. I have one requirement in Cron jobs for FTP Download. Presently i am

downloading around 600 MB files from ftp server manually in every monday. This will affect our internet bandwidth

during office hours. For avioding this, i am planning to schedule cron jobs for my download process.

Download Process to be performed in SUSE Linux. Becoz Downloaded files to be replaced into that server only.

My requirement,

1) I have to stop my server before start the download process. I have given below scripts for stop server process

manually.

login as endeca
password end123

a)endeca# . .endeca_apt
b)endeca# cd bin/
c)endeca/bin# RunCommand apt_control.script apt_stop

a)endeca# . .endeca_auto
b)endeca# cd bin/
c)endeca/bin# RunCommand auto_control.script auto_stop

a)endeca# . .endeca_chrome
b)endeca# cd bin/
c)endeca/bin# RunCommand chrome_control.script chrome_stop

a)endeca# . .endeca_babe
b)endeca# cd bin/
c)endeca/bin# RunCommand babe_control.script babe_stop

How can i write scripts with should be stopped my server process in differnt user?

2) I have to download files from four source folders Like /Source/Dumps1/, /Source/Dumps2/, /Source/Dumps2/*,

/Source/Dumps2/*. This will possible on root user only.

FTP Host is 10.10.10.100 port 21
user abc
password defgh

3) Downloaded files are replaced into my Destination folder like /space/endeca/apt/, /space/endeca/auto/,

/space/endeca/chrome/, /space/endeca/babe/ - This will possible on root user only. Is there need to delete the old

files in that four folders?

4) Once Files are moved into destination path. I have to change the ownership of that files like below

root# chown endeca:endeca /space/endeca/apt
root# chown endeca:endeca /space/endeca/auto
root# chown endeca:endeca /space/endeca/chrome
root# chown endeca:endeca /space/endeca/babe

5) Once change ownership is over, i have to restart the server process

login as endeca
password end123

a)endeca# . .endeca_apt
b)endeca# ./start_em.sh
c)endeca# cd bin/
d)endeca/bin# RunCommand apt_control.script apt_start

a)endeca# . .endeca_auto
b)endeca# ./start_em.sh
c)endeca# cd bin/
d)endeca/bin# RunCommand auto_control.script auto_start

a)endeca# . .endeca_chrome
b)endeca# ./start_em.sh
c)endeca# cd bin/
d)endeca/bin# RunCommand chrome_control.script chrome_start

a)endeca# . .endeca_babe
b)endeca# ./start_em.sh
c)endeca# cd bin/
d)endeca/bin# RunCommand babe_control.script babe_start

I have written ftp scripts for download. My doubt is i have to write four script for downloading four folders. Also

i have to schedule four cron jobs for my tasks.

#!/bin/bash -vx
ftp -in 10.10.10.100<<END_SCRIPT
quote USER abc
quote PASS defgh
bin
prompt off
cd /Source/Dumps1/
lcd /space/endeca/apt/
mget *
bye
END_SCRIPT

Please don't take bore of my post.

Thanks in advance,

Moorthy.GS

You can do the task by means of a single shell script itself and by means of a single cron?

Hey,

Thanks for your reply.

Hope it is not possible for single shell script. But it can possible on single cron job.

Please guide me.

Cheers,

Moorthy.GS

#!/bin/bash -vx
ftp -in 10.10.10.100<<END_SCRIPT
quote USER abc
quote PASS defgh
bin
prompt off
cd /Source/Dumps1/
lcd /space/endeca/apt/
mget *
cd ..
cd Dumps2/
lcd /space/endeca/auto/
mget *
cd ..
cd Dumps3/
lcd /space/endeca/chrome/
bye
END_SCRIPT

I think the above script will do the task for you,if you schedule it through crontab.

With Regards
Dileep Pattayath

Hey Dillip,

Thanks for your guidance,

I modified your shellscript as per my requirement. code is below

#!/bin/bash -vx
ftp -in 10.10.10.100<<END_SCRIPT
quote USER abc
quote PASS abcded
bin
prompt off
cd /csi/endeca_chrome/dgraph_input/
lcd /home/endeca/chrome/
mget *
cd ..
cd /csi/endeca_autos/dgraph_input/
lcd /home/endeca/autos/
mget *
cd ..
cd /csi/endeca_babe/dgraph_input/
lcd /home/endeca/babe/
mget *
cd ..
cd /csi/endeca_apt/dgraph_input/
lcd /home/endeca/babe/
mget *
bye
END_SCRIPT

I have scheduled last night 2 AM for my download process. Here below crontab entries....

00 02 * * 2 /root/ftp.sh > /root/ftp.log 2>&1

But only 3 files copied to /home/endeca/chrome/ location.

I have pasted my ftp.log entries for your reference. Please help to fix it.

#!/bin/bash -vx
ftp -in 216.251.248.151<<END_SCRIPT
+ ftp -in 216.251.248.151
Interactive mode off.
Local directory now /home/endeca/chrome
'EPSV': command not understood

Cheers,

Moorthy.GS

Please try the below code :

#!/bin/bash -vx
ftp -in 10.10.10.100<<END_SCRIPT
quote USER abc
quote PASS abcded
bin
prompt off
cd /csi/endeca_chrome/dgraph_input/
lcd /home/endeca/chrome/
mget *
cd /csi/endeca_autos/dgraph_input/
lcd /home/endeca/autos/
mget *
cd /csi/endeca_babe/dgraph_input/
lcd /home/endeca/babe/
mget *
cd /csi/endeca_apt/dgraph_input/
lcd /home/endeca/babe/
mget *
bye
END_SCRIPT

It's working for me and also take a look at the permissions fot the files.

'EPSV': command not understood
was not an error.It was trying to use the extended passive mode ftp.If it was not supported it will automaticall return back to PASV mode.

With Regards
Dileep Pattayath