Shell script to automatically download files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to automatically download files
# 1  
Old 07-08-2010
Shell script to automatically download files

I am new to shell scripting and need to write a program to copy files that are posted as links on a specific url. I want all the links copied with the same file name and the one posted on the webpage containing the url onto a specific directory. That is the first part. The second part of the script is to delete the files from the directory that are older than 3 days. Normally, I use "wget filename" from the specified directory then simply delete with the remove command manually. How would I set up the script to run automatically, twice daily? Thanks.
# 2  
Old 07-08-2010
Do you know the name of the file you are downloading? Or just that the name will be on a web page?

If you know the exact name(s), you can just run the wget command like you've done before. (So what would be the question?) But if you have to get the name from a web page, you may have to scrape the name out of the html using grep, sed, or awk, etc.


For the second part, the simplest way is to do a loop with something like
sleep 12h
to delay. But then you couldn't log out.

A better way is to make a cron job, something like this:
Code:
echo '* 1,13 * * * $HOME/bin/myscript' | crontab

The first five parameters are minute, hour, day, month, day-of-week. 1,13 means run it at 1:00 AM and 1:00 PM.

Don't put any loop in myscript, just run once and exit. Cron will run it again in 12 hours.
# 3  
Old 07-12-2010
Download Changing linked filenames

There are numerous files that must be downloaded from the site twice daily. The file names change based on date. Looking at the system, I am thinking the the script must also remove the files first before downloading new ones because there will be some overlap in the dates. The site I am downloading the files from is Index of /tiziana/rhuff there are two subdirectories which will be based on the year month and date. The latter contains the more recent files. I wanted to store the files for three days but I don't think that is possible unless I rename the files in the script prior to downloading the new ones. So just to keep it simple lets say I remove all files prior to copying the new ones. So there are three things that need to be done.

1.Remove the current files.
That could be done with a simple remove all files from directory (but keep the directory) command which I am not sure how to do.

2. Have a command copy ALL FILES and keep the same file name conventions stored on a specified directory.

3. Repeat twice daily at a specified time.

I understand what you are saying about the crontab function. Am I correct in assuming that I would need to write a script that does functions 1 & 2 and then enter the function manually that used the crontab function to initiate the script automatically with the name of the script being bin/myscript based on your prior post? If so, How would I write the code for the first two steps?
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to download compressed archive zips in bulky automatically using wget?

How to download in bulky compressed (zip, 7z, bzip, xz, etc) archive files from a repository automatically by use of wget ? (3 Replies)
Discussion started by: abdulbadii
3 Replies

2. Shell Programming and Scripting

Hundreds of files need manual preparation. Does shell script could do it automatically?

Hello friends, I have hundreds files in hand, which need extract some data from logs and read these data into an input file. Here I will explain in detail using these two files as attached. read some data from .log file and write it into the .in file. **explanation is given inside two... (9 Replies)
Discussion started by: liuzhencc
9 Replies

3. Shell Programming and Scripting

Shell Script for Upload/download files using cURL

hi please help me out here, i want to use curl command in shell script to test web pages, what i have is an opening page, when i click on a button on opening page, the next page comes up and then i have to upload a file n then click another button to submit and then comes the output page,... (2 Replies)
Discussion started by: Olivia
2 Replies

4. Shell Programming and Scripting

shell script to download variables files

Hello all i am working on creating shell script to download files daily example : file12_10_2009.txt.gz next day this file will be file13_10_2009.txt.gz and so on.. i need help to know how to download this incrimental date files daily ? regards (1 Reply)
Discussion started by: mogabr
1 Replies

5. Shell Programming and Scripting

Shell script to invoke options automatically

i have a script which has 2 options. a b And a has 6 sub options. i want to write a script which will call the parent script and give options automatically. examle: linasplg11:/opt/ss/kk/01.00/bin # startup.sh /opt/ss/rdm/01.00 Please select the component to... (2 Replies)
Discussion started by: Aditya.Gurgaon
2 Replies

6. Linux

shell script to download files from a site?

Hey everyone, my wife has purchased a bundle package of a bunch of images from a site, and now has to download each one of them manually. There are about 500 downloads, and it's quite a hassle to browse to each page and download them all individually. I would like to write a shell script to... (2 Replies)
Discussion started by: paqman
2 Replies

7. Shell Programming and Scripting

how to run shell script automatically

hi , i m trying to run bash scrip automaticially but i dont know how i can do this an anybody tell me how i can autorun shell script when i logon . thanks (9 Replies)
Discussion started by: tahir23
9 Replies

8. Shell Programming and Scripting

Script to automatically check ports in shell?

Good day, I'm new to linux environment...Is there any scripts available for me to check ports (lets say port 80 and 21) through shell with just a single commandline? Any response is very much appreciated.. thanks (4 Replies)
Discussion started by: arsonist
4 Replies
Login or Register to Ask a Question