On Mon, 28 Mar 2005 16:09:09 -0800 Jonathan Nichols <[EMAIL PROTECTED]> wrote:
> (Note: I suck at Perl.) > > I have a script. it's a simple script. > > #!/usr/bin/perl > $file = "foo.txt"; > system"wget http://clutter.pbp.net/~jnichols/foo.txt" || die "Couldn't > get $file"; > > Currently "foo.txt" doesn't exist. It'll return a 404. It doesn't die > with the error message above. Basically, I need wget to die and return > the specified error message if the result is *anything* but successful. > If wget gets the file, ok. If it fails to get the file for any reason, > barf out. > > Sounds simple enough, eh? I can't seem to find documentation on how to > achieve this goal. Help? :P Well, if you're using perl, check out the LWP::Simple module. Here's an (untested) snippet: #!/usr/bin/perl use strict; use LWP::Simple ('get', 'getstore'); my $link = 'http://clutter.pbp.net/~jnichols/foo.txt'; my $filename = substr $link, (rindex $link, '/') + 1; print $filename, "\n"; if (( getstore ($link, $filename)) != 200){print 'failure'}else{print 'success'} HTH... -- |\ /| | | ~ ~ | \/ | |---| `|` ? | |ichael | |iggins \^ / michael[dot]higgins[at]snet[dot]net -- gentoo-user@gentoo.org mailing list