Is there a better way

Is there a better way

am 12.12.2005 21:03:27 von Marg

Hi,

I'm doing this script (after my signature) that starts by downloading
files from the web.
It checks for each file if the download was successful.

Is theres a fancier way to do the test, instead of repeating
-----------------------------------
code=$?
if [ $code != 0 ]
then
echo "Couldn't retrieve file :("
exit 1
fi
-----------------------------------

for each file ?

Any help would be apreciated.

Warm Regards,
MARG

#!/bin/bash

cd /usr/local/src
wget
http://www.mirror.ac.uk/mirror/ftp.apache.org/httpd/apache_1 .3.34.tar.gz
code=$?
echo $code
if [ $code != 0 ]
then
echo "Couldn't retrieve file :("
exit 1
fi
wget
http://www.mirror.ac.uk/mirror/www.mysql.org/Downloads/MySQL -5.0/mysql-5.0.16.tar.gz
code=$?
echo $code
if [ $code != 0 ]
then
echo "Couldn't retrieve file :("
exit 1
fi
wget
http://www.mirror.ac.uk/mirror/ftp.postgresql.org/v8.1.1/pos tgresql-8.1.1.tar.bz2
code=$?
echo $code
if [ $code != 0 ]
then
echo "Couldn't retrieve file :("
exit 1
fi
wget
http://www.mirror.ac.uk/mirror/ftp.openssl.org/source/openss l-0.9.8a.tar.gz
code=$?
echo $code
if [ $code != 0 ]
then
echo "Couldn't retrieve file :("
exit 1
fi
wget
http://www.mirror.ac.uk/mirror/ftp.modssl.org/source/mod_ssl -2.8.25-1.3.34.tar.gz
code=$?
echo $code
if [ $code != 0 ]
then
echo "Couldn't retrieve file :("
exit 1
fi
wget http://www.mirror.ac.uk/mirror/ftp.apache.org/perl/mod_perl- 1.29.tar.gz
code=$?
echo $code
if [ $code != 0 ]
then
echo "Couldn't retrieve file :("
exit 1
fi
wget http://www.modsecurity.org/download/modsecurity-apache-1.9.1 .tar.gz
code=$?
echo $code
if [ $code != 0 ]
then
echo "Couldn't retrieve file :("
exit 1
fi
wget
http://puzzle.dl.sourceforge.net/sourceforge/mcrypt/libmcryp t-2.5.7.tar.gz
code=$?
echo $code
if [ $code != 0 ]
then
echo "Couldn't retrieve file :("
exit 1
fi
wget http://puzzle.dl.sourceforge.net/sourceforge/mhash/mhash-0.9 .3.tar.gz
code=$?
echo $code
if [ $code != 0 ]
then
echo "Couldn't retrieve file :("
exit 1
fi
wget http://puzzle.dl.sourceforge.net/sourceforge/mcrypt/mcrypt-2 .6.4.tar.gz
code=$?
echo $code
if [ $code != 0 ]
then
echo "Couldn't retrieve file :("
exit 1
fi
wget
http://www.mirror.ac.uk/mirror/rsync.php.net/distributions/p hp-5.1.1.tar.bz2
code=$?
echo $code
if [ $code != 0 ]
then
echo "Couldn't retrieve file :("
exit 1
fi
wget http://neacm.fe.up.pt/pub/apache/httpd/modpython/mod_python- 2.7.11.tgz
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Is there a better way

am 12.12.2005 21:25:13 von Scott Taylor

MARG said:
> Hi,
>
> I'm doing this script (after my signature) that starts by downloading
> files from the web.
> It checks for each file if the download was successful.
>
> Is theres a fancier way to do the test, instead of repeating
> -----------------------------------
> code=$?
> if [ $code != 0 ]
> then
> echo "Couldn't retrieve file :("
> exit 1
> fi
> -----------------------------------
>
> for each file ?

How about putting your links in a nice file

for link in `cat mylinksfile`; do

wget $link
blah blah blah
done

using && in place of ; might help too, as the next command (after &&) only
gets ran if the first was error free.

also if [!$?] should work in this case as well (test it though)

> Any help would be apreciated.

You need a book on UNIX Shell scripting. There are loads of free stuff
out there. :)

--
Scott

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Is there a better way

am 12.12.2005 21:36:15 von foo

Or so, if you dont trust the "&&"

#!/bin/bash
for pkgurl in $(cat pkg-url-list.txt); do
wget $pkgurl ;
code=$?
echo $code
if [ $code != 0 ]
then
echo "Couldn't retrieve file :("
###break loop instead of exit 1
break
fi

done


--Adrian


>MARG said:
> > Hi,
> >
> > I'm doing this script (after my signature) that starts by downloading
> > files from the web.
> > It checks for each file if the download was successful.
> >
> > Is theres a fancier way to do the test, instead of repeating


-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Is there a better way

am 12.12.2005 22:01:11 von Scott Taylor

Adrian C. said:
>
> Or so, if you dont trust the "&&"
>
> #!/bin/bash
> for pkgurl in $(cat pkg-url-list.txt); do
> wget $pkgurl ;
> code=$?
> echo $code
> if [ $code != 0 ]
> then
> echo "Couldn't retrieve file :("
> ###break loop instead of exit 1
> break
> fi
>
> done

Also, may want to add the variable to your error message so you know which
file it couldn't get:
echo "Couldn't retrieve file: $pkgurl :("

--
Scott

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Is there a better way

am 12.12.2005 22:09:58 von foo

That's a tad redundant because wget already yells it cannot find URL x.

--Adrian


>Also, may want to add the variable to your error message so you know which
>file it couldn't get:
> echo "Couldn't retrieve file: $pkgurl :("
>
>--
>Scott
>
>-
>To unsubscribe from this list: send the line "unsubscribe linux-admin" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at http://vger.kernel.org/majordomo-info.html


-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html