FTP a file on Hourly basis


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP a file on Hourly basis
# 1  
Old 05-28-2011
Bug FTP a file on Hourly basis

Hi,

I have to upload a file test_201105281100.txt to a ftp location.

The files will be created on hourly basis like test_201105281100.txt, test_201105281200.txt & so on.

After a file is uploaded successfully, I need to rename the file as test_201105281100.success & if it is not uploaded successfully then rename it as test_201105281100.failure.

Also I need to delete the older files ( I may delete all the files or only .success files). After 12 AM on 30th May, I want to delete all the files that were created on 28th.

I want the script to run as a cron job.

Please help.

Note: I will be able to implement & test the solution that you suggest on Monday morning (more than 36 Hours from now).

Thanks,
Sunil
# 2  
Old 05-28-2011
I didnt test this. Hope this will work. I have given just a skeleton you need some work to make this work.

Code:
upload()
{
  ftp $hostname
  user $user_name
  password $password
  put $file_name 
  bye
}
checkupload()
{
  ftp $hostname
  user $user_name
  password $password
  get ${file_name} ${file_name}.remote
  bye

loc=`wc -c ${file_name}`
rem=`wc -c ${file_name}.remote`

if [ $loc -eq $rem ]
then
  echo "file uploaded successfully.."
  mv $file_name ${file_name}.success
else 
 echo "file uploaded failed.."
   mv $file_name ${file_name}.failure
fi
}

  
# assign values for below variables
file_name=
user_name=
password=
hostname=

upload
checkupload


Last edited by luckybalaji; 05-29-2011 at 07:33 AM.. Reason: correcting known mistakes
This User Gave Thanks to luckybalaji For This Post:
# 3  
Old 05-30-2011
Bug I need more solutions

Hi Friends,

I need some more solutions.

Kindly help at the earliest.

Thanks,
Sunil
# 4  
Old 05-30-2011
Bug Not logging to FTP automatically

Quote:
Originally Posted by luckybalaji
I didnt test this. Hope this will work. I have given just a skeleton you need some work to make this work.

Code:
upload()
{
  ftp $hostname
  user $user_name
  password $password
  put $file_name 
  bye
}
checkupload()
{
  ftp $hostname
  user $user_name
  password $password
  get ${file_name} ${file_name}.remote
  bye
 
loc=`wc -c ${file_name}`
rem=`wc -c ${file_name}.remote`
 
if [ $loc -eq $rem ]
then
  echo "file uploaded successfully.."
  mv $file_name ${file_name}.success
else 
 echo "file uploaded failed.."
   mv $file_name ${file_name}.failure
fi
}
 
 
# assign values for below variables
file_name=
user_name=
password=
hostname=
 
upload
checkupload

Hi,

I have set the variables as follows.

Code:
bash-2.03# echo $hostname
97.253.98.14
bash-2.03# echo $password
postgres
bash-2.03# echo $file_name
ONLINE_WAIVER_2011052816.txt
bash-2.03# echo $user_name
postgres
bash-2.03#

I have created the 2 scripts as follows.

Code:
bash-2.03# cat f.sh
#!/bin/bash
source upload.sh
upload
bash-2.03#

and

Code:
bash-2.03# cat upload.sh
#!/bin/bash
function upload(){
  ftp $hostname
  user $user_name
  password $password
  put $file_name
  bye
}
bash-2.03#

But on running the script, I am not able to login to FTP automatically.

Code:
bash-2.03# ./f.sh
ftp> ls
Not connected.
ftp>

Thanks,
Sunil
# 5  
Old 05-30-2011
you have to use

Code:
ftp -inv $hostname
user $user_name $pass_word

This User Gave Thanks to kumaran_5555 For This Post:
# 6  
Old 05-30-2011
Bug Still not able to login to FTP

Quote:
Originally Posted by kumaran_5555
you have to use

Code:
ftp -inv $hostname
user $user_name $pass_word

Hi,

Still not able to login to FTP from the script.

Code:
bash-2.03#
bash-2.03# echo $hostname
97.253.98.14
bash-2.03# echo $user_name
postgres
bash-2.03# echo $pass_word
postgres
bash-2.03# echo $file_name
ONLINE_WAIVER_2011052816.txt
bash-2.03#
bash-2.03#
bash-2.03#
bash-2.03# cat f.sh
#!/bin/bash
source upload.sh
upload
bash-2.03#
bash-2.03#
bash-2.03#
bash-2.03# cat upload.sh
#!/bin/bash
function upload(){
ftp -inv $hostname
user $user_name $pass_word
#Password $password
put $file_name
  bye
}
bash-2.03#
bash-2.03#
bash-2.03# ./f.sh
ftp> ls
Not connected.
ftp>

Thanks,
Sunil

Last edited by SunilB2011; 05-30-2011 at 07:08 AM..
# 7  
Old 05-30-2011
Code:
function upload(){
  ftp -inv $hostname <<EOF
  user $user_name $pass_word
  put $file_name
  bye
EOF
}

This will work. You wrote the function wrong.

Last edited by Franklin52; 05-30-2011 at 07:30 AM.. Reason: Please use code tags, thank you
This User Gave Thanks to kumaran_5555 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combining files(every 15 min) as one file(hourly)

Hello, My system is generating two files every 15 minutes and file names are given automatically as below. (98,99,89,90 are the sequence numbers) File1_09242013131016_000000098 File1_09242013131516_000000099 File2_09242013124212_000000089 File2_09242013124712_000000090 I want to combine... (6 Replies)
Discussion started by: phoenex11
6 Replies

2. Shell Programming and Scripting

Calculate avg response time on hourly basis

Hi, I am trying to calculate avg response time on hourly basis from the log file which has millions of records. As of now I am trying with creating temp file which will have lines with unique id and start time and end time and after that another script will run on this temp file to... (7 Replies)
Discussion started by: random_thoughts
7 Replies

3. Shell Programming and Scripting

Crontab on hourly basis

Hi.. I need to run the script on hourly basis. How do I write the crontab on hourly basis i.e, 9:00, 10:00.....22:00.. 23:00 hours Please let me know if the below is correct one for crontab on hourly basis. 00 * * * * ksh myscript.ksh > /dev/null Regards, John (3 Replies)
Discussion started by: scriptscript
3 Replies

4. Shell Programming and Scripting

Create log file periodically ex: hourly

Hello, I have a command which runs continuously and creates output to STDOUT. Now, in unix, if I create logging for this command, it would create a single log file and keep on updating. As there is so much data filled in it, I would want to break the log files periodically. In this instance, say... (4 Replies)
Discussion started by: rajkumarme_1
4 Replies

5. Shell Programming and Scripting

how to grep string from hourly basis files

dear all, pls help on this script.. i have many files which will be created every mins in particular directory. i want to grep a particular string from only for unique hour files. from the below code i want to grep a string from only 9th hour files . Ex files: -rw-r--r-- 1 root ... (5 Replies)
Discussion started by: steve2216
5 Replies

6. Shell Programming and Scripting

Increment #'s in text file hourly

I have a text file with a number "001". I am trying to change this number every hour and increment by "1". So every hour it would add +1 to that number. I am able to change the file with sed but unable to have it increment it by "1" without me adding that to the sed command. Any help is... (23 Replies)
Discussion started by: noob33
23 Replies

7. Solaris

Monitoring the output of 'top' command on hourly basis.

I need to capture the following data on an hourly basis through cronjob scheduling:- 1. load averages 2. Total no. of processes. 3. CPU state 4. Memory 5. Top 3 process details. All the above information is available through the command 'top'. But here we need to automate the same and... (4 Replies)
Discussion started by: subharai
4 Replies

8. UNIX for Dummies Questions & Answers

count string occurance in a file hourly

Hi, I file that has all the status for one day (24hours). Now what I want to do is to count the occurence of a string in its output hourly like for example count occurance of successful or asynchronous clear destinon for every hour and redirect it to file. Please see sample file below. Please... (2 Replies)
Discussion started by: ayhanne
2 Replies

9. UNIX for Dummies Questions & Answers

How do you automate an hourly file check?

Hi, New to the forum, Great site, I can learn a lot from here!! :cool: I would like to know how to automate a command that checks the Sybase database's are "alive" on an hourly basis, and mails outlook if they are not (1 Reply)
Discussion started by: mals
1 Replies
Login or Register to Ask a Question