Solved

Linux wget BASH script

Posted on 2004-09-30
2
1,626 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 300 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Percona cluster member randomly crash 15 353
what is Amazon Linux AMI 6 53
Identify Linux loader 67 163
linux $PWD 2 537
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now