LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-06-2004, 10:49 PM   #1
greenhornet
Member
 
Registered: Mar 2002
Location: Sydney, Australia
Distribution: RHEL, Fedora, Yellow Dog
Posts: 43

Rep: Reputation: 15
GNU wget return codes for shell script


Hi All,

I'm trying to use GNU wget in a bash shell script to automate the download of virus identities to my linux webserver which will then in turn be picked up by my windows clients. I am using wget timestamping to only download the file if it has changed on the vendors site, I also need to make a copy of this file into a standard name that all my windows clients can use.

At the moment I have;

Code:
#!/bin/sh

if `wget -N http://www.sophos.com/downloads/ide/380_ides.exe`; then
      cp -f 380_ides.exe ides.exe
      echo "IDEs were updated."
else
      echo "IDEs do not need to be updated."
fi
However in the instance where wget does not download the 380_ides.exe file because it is no newer that the one it downloaded last time it still evaluates the "if" and remakes the ides.exe file. My windows clients are also using wget and so they are always thinking the file ides.exe is new and as such are always hammering my webserver for updates they don't need.

I cannot find any documentation on wget return codes on the GNU site. Does anyone know how I can make this work?

thanks heaps,
GH
 
Old 05-07-2004, 12:56 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
It seems that the return code doesn't indicate whether the file needs to be update or not. But you can test the timestamps of the two files on your drive. I tested the code below and it worked.

Code:
#!/bin/bash

wget -N http://www.sophos.com/downloads/ide/380_ides.exe
if [[ 380_ides.exe -nt ides.exe ]]; then
        cp -f 380_ides.exe ides.exe
        echo "IDEs were updated."
else
        echo "IDEs do not need to be updated."
fi
The -nt stands for newer then.

Last edited by jschiwal; 05-07-2004 at 01:00 AM.
 
Old 05-07-2004, 02:18 PM   #3
lyle_s
Member
 
Registered: Jul 2003
Distribution: Slackware
Posts: 392

Rep: Reputation: 55
Yet another approach:

Code:
#!/bin/bash

DOWNLOAD_DIR=http://www.sophos.com/downloads/ide
DOWNLOAD_FILE=380_ides.exe
LOCAL_NAME=ides.exe


# Attempt to download the file. --progress=dot:mega is used to prevent
# WGET_OUTPUT from getting too long.
WGET_OUTPUT=$(2>&1 wget --timestamping --progress=dot:mega \
              "$DOWNLOAD_DIR/$DOWNLOAD_FILE")


# Make sure the download went okay.
if [ $? -ne 0 ]
then
	# wget had problems.
	echo 1>&2 $0: "$WGET_OUTPUT"  Exiting.
	exit 1
fi


# Copy the file to the new name if necessary.
if echo "$WGET_OUTPUT" | fgrep 'saved' &> /dev/null
then
	cp -f "$DOWNLOAD_FILE" "$LOCAL_NAME"
	echo "IDEs were updated."
else
	echo "IDEs do not need to be updated."
fi
Lyle

Last edited by lyle_s; 05-07-2004 at 02:21 PM.
 
1 members found this post helpful.
Old 05-09-2004, 07:51 PM   #4
greenhornet
Member
 
Registered: Mar 2002
Location: Sydney, Australia
Distribution: RHEL, Fedora, Yellow Dog
Posts: 43

Original Poster
Rep: Reputation: 15
Thanks heaps guys, both these solutions work a treat and are now saving my webserver a lot of unessicary work!!

cheers!
GH
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can a C function return value to Shell Script variable yarnar Programming 17 06-02-2010 05:54 PM
mprotect() return codes tim_l Programming 2 05-09-2005 07:38 AM
return codes in c exvor Programming 4 01-21-2005 08:45 PM
return value from shell script to c code? khucinx Programming 1 05-13-2004 03:43 PM
return key on shell script chupacabra Programming 2 10-22-2002 12:11 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration