Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Linux wget BASH script

Posted on 2004-09-30
2
Medium Priority
?
1,668 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

722 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