Solved

Linux wget BASH script

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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

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 demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

636 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