Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Linux wget BASH script

Posted on 2004-09-30
2
Medium Priority
?
1,676 Views
Last Modified: 2008-02-01
Hello all,

I'm trying to write a script to wget files in a url list then when done echo the successful downloads / total downloads attempted. Any ideas on this?
0
Comment
Question by:GR999
2 Comments
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 1200 total points
ID: 12195670
Try this:

#!/bin/sh

url_list="http://url1 http://url2"

failed=0
failed_urls=""
success=0
success_urls=""

for i in $url_list; do
        wget -q $i
        res=$?
        if [ $res -eq 0 ] ; then
                (( success++ ))
                success_urls="$success_urls $i"
        fi
        if [ $res -ne 0 ] ; then
                (( failed++ ))
                failed_urls="$failed_urls $i"
        fi
done


echo "$success successful downloads:"
for i in $success_urls ; do
        echo $i
done
echo "$failed failed downloads"
for i in $failed_urls ; do
        echo $i
done
# end of script

Set the url_list variable to the URLs you want to download. You can of course also change the wget parameters.
0
 

Author Comment

by:GR999
ID: 12202656
Wow nice job! Works great just modified the url list stuff. Much better than what i had originally as I am fairly new to scripting. This is what I had started with...bear with me I only have a very small grasp of programming:

#!/bin/bash

SAVED=0
PKGS=0


echo "What file should I use?"
read urllist

for i in $(cat $urllist); do
wget $i
 if $? > 0
 then PKGS=$[$PKGS + 1]
 elif $? = 0
 then
        SAVED=$[$SAVED + 1]
        PKGS=$[$PKGS + 1]
 fi

done

echo "The files successfully downloaded is $SAVED/$PKGS "

##End Script

This would do its job, but the last echo would not be accurate. Anyway I appreciate your help, thnx alot!!

GR
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question