• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Bash help

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Shelnutt2

Overclockers Team Content Editor
Joined
Jun 17, 2005
Location
/home/
I'm trying to figure this out but I can't seem to get it.

when I run,
Code:
wget http://www.filehippo.com/download/file/62d453bcd76a17595775722491a01e0ca6f1eb54518073f3d81c4b8f141c92a9/

it downloads and saves the file to "Firefox Setup 3.6.3.exe". I need to be able to figure out the file name. I'm running a script and what I need to be able to set $NAME to "Firefox Setup 3.6.3.exe", however I'll be downloading different things with the script to how can I get the name of the file that is being downloaded?

I thought about greping the log files but that seems overly complicated for this task.


edit:

Here is my whole script, I am getting a problem running it on line 50, It is saying that "./GetUpdatesFromFilehippo.sh: line 50: Saving to:: command not found "

When I run line 50 from the cli it works fine. I don't understand why it's failing in this script?

edit edit:
Fixed! Here is my working code for reference
Code:
FILENAME=$(grep "Saving to:" $TEMPLOG | $AWK 'BEGIN { FS="`" } { print $2 }')

Code:
#!/bin/bash

# script to check for new versions of a package from filehippo.com
# NOTE: If you call this for multiple packages, PLEASE put a delay (5-10 seconds)
# between each call so that you don't over-stress the server!

if [ -z "$1" ]; then
  echo "Downloads the latest version of a package from filehippo.com."
  echo
  echo "Usage: $0 <package name>"
  echo
  echo "  where <package name> is the name of the filehippo.com package."
  echo
  echo "Example, URL for Mozilla Firefox is http://www.filehippo.com/download_firefox/"
  echo "so package name is part of the URL after \"download_\", or \"firefox\"."
  exit 1
fi

PACKAGE=$1
BASEURL=http://www.filehippo.com
URL=$BASEURL/download_$PACKAGE
TEMPFILE=/tmp/$PACKAGE.html
TEMPLOG=/tmp/$PACKAGE.log
EXEDIR="software/$PACKAGE"
XMLDIR="packages"
VERION='grep revision $XMLDIR/$PACKAGE.xml | $AWK 'BEGIN { FS="=" } { print $2 }''

if [ ! -d "$EXEDIR" ]; then
    mkdir -p $EXEDIR
fi


if [ ! -d "$XMLDIR" ]; then
    mkdir -p $XMLDIR
fi



WGET="wget"
AWK="awk"
AGENT="Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"
WGETOPTIONS="-t 0 -T 300"

$WGET $WGETOPTIONS -U "$AGENT" -O $TEMPFILE --header="Cookie: Filter=NOBETA=1&NODEMO=0" $URL

NEWVERSION=`grep "<h1>" $TEMPFILE | $AWK 'BEGIN { FS=">" } { print $2 }' | $AWK 'BEGIN { FS="<" } { print $1 }'`

REVISION1=`grep "<h1>" $TEMPFILE | $AWK 'BEGIN { FS=">" } { print $2 }' | $AWK 'BEGIN { FS="<" } { print $1 }' | $AWK 'BEGIN { FS=" " } { print $2 }' | $AWK 'BEGIN { FS="." } { print $1 }'`
REVISION2=`grep "<h1>" $TEMPFILE | $AWK 'BEGIN { FS=">" } { print $2 }' | $AWK 'BEGIN { FS="<" } { print $1 }' | $AWK 'BEGIN { FS=" " } { print $2 }' | $AWK 'BEGIN { FS="." } { print $2 }'`
REVISION3=`grep "<h1>" $TEMPFILE | $AWK 'BEGIN { FS=">" } { print $2 }' | $AWK 'BEGIN { FS="<" } { print $1 }' | $AWK 'BEGIN { FS=" " } { print $2 }' | $AWK 'BEGIN { FS="." } { print $3 }'`

if (( "${#REVISION3}" < 2 )); then
REVISION3=$(echo "0"$REVISION3)
fi
REVISION=$(echo $REVISION1$REVISION2$REVISION3)

DOWNLOADURL1=$BASEURL`grep "<b>Download<br/>Latest Version</b>" $TEMPFILE | $AWK 'BEGIN { FS="\"" } { print $2 }'`

# delay so don't overload the server.
sleep 1

$WGET $WGETOPTIONS -U "$AGENT" -O $TEMPFILE --header="Cookie: Filter=NOBETA=1&NODEMO=0" $DOWNLOADURL1
DOWNLOADURL2=$BASEURL`grep "Refresh" $TEMPFILE | $AWK 'BEGIN { FS="=" } { print $4 }' | $AWK 'BEGIN { FS="\"" } { print $1 }'`

echo Current version = $VERSION
echo New Version = $NEWVERSION
echo Download URL = $DOWNLOADURL2

# if the file to download already exists, we are done.
if [ ! -f "$EXEDIR/$NEWVERSION.exe" ]; then
  echo "New version available... downloading..."
  cd $EXEDIR && $WGET $WGETOPTIONS -U "$AGENT" $DOWNLOADURL2 -o $TEMPLOG && cd ../..
FILENAME=$(grep "Saving to:" $TEMPLOG | $AWK 'BEGIN { FS="`" } { print $2 }')

  # create a new package.xml file

echo  "<?xml version=\"1.0\" encoding=\"UTF-8\"\?>

<packages>

<package
   id=\"$PACKAGE\"
   name=\"$NEWVERSION\"
   revision=\"$REVISION\"
   reboot=\"false\"
   priority=\"10\">

   <install cmd='\"%SOFTWARE%\\$PACKAGE\\$FILENAME\" -ms' />

   <upgrade cmd='\"%SOFTWARE%\\$PACKAGE\\$FILENAME\" -ms' />

</package>

</packages>
" > $XMLDIR/$PACKAGE.xml
else
  echo "$EXEDIR/$NEWVERSION.exe exists, so not downloading anything."
fi

# clean up temp file
rm -f $TEMPFILE
rm -f $TEMPLOG

# delay so back-to-back calls of thie script don't overload the server.
sleep 10
 
Last edited:
Looks pretty good. What was the overall point of this script? Are you planning on publishing it or is it just an in-house thing?
 
Back