Register
It is currently Sat Apr 19, 2014 11:43 pm

Wget sometimes works in script, other times returns error


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Fri Sep 05, 2008 8:40 am   

Joined: Fri Sep 05, 2008 7:50 am
Posts: 3
Location: Graduate School
I'm writing a simple script to download a file from a website using wget. Wget is installed and works in a small script but when added to a much larger script it doesn't work and the command line returns "line 31: wget: No such file or directory" (I deleted some unnecessary commenting so the error proly is no longer on line 31 but is still there.)

Here is the simple script that works fine:
Code:
#!/bin/bash
echo some stuff
FLAG=1
if [ $FLAG = 1 ];
then
eval wget http://zvbxrpl.org/index.html
fi

and here is the code that I receive the error on.
The basics of the code are to try the base filename and if the download for that filename is unsuccessful to try a filename with a letter added on to the end.
Code:
#!/bin/bash
# argument list 1) date in mdy format 2) path to file folder where file should exist 3) login 4) password
#http://ubuntuforums.org/showthread.php?t=745486 for code to check if file exists
#http://ubuntuforums.org/archive/index.php/t-659624.html looking for way to increment file extension letter

#variables
PASSWORD=XXXXX
LOGIN=XXXXXX
extension=.pdf
alf=(a b c d e f g h i j k l m n o p q r s t u v w x y z) #indices start at 0
index=0 #indices start at 0
PATH=$2
date=$1
STOPFLAG=0

#echo ${alf[$index]} #test array index

if [ $# != 1 ];
then echo We need the date as an argument.
else

   filename=eibd$date$extension #for some reason eibd$datea.pdf wouldn't produce e.g. eibd040908a.pdf
   echo Initially trying to get $filename.

   if [ -e /home/min/a/nkloster/$filename ];
#   if [ -e $PATH$filename ];
      then echo File $filename all ready downloaded!
   else
      
      eval wget http://eibd.investors.com/pdfibd/$filename --http-use=$LOGIN --http-passwd=$PASSWORD
      
      echo eval wget http://eibd.investors.com/pdfibd/$filename --http-use=$LOGIN --http-passwd=$PASSWORD

#if file doesn't exist then increment to a b c d


#need a while loop to check if the file exists and to keep checking for it otherwise
      while [ ! -e /home/nicky/$filename ] && [ $STOPFLAG -ne 1 ]
      do
         filename=eibd$date${alf[$index]}$extension
         echo $filename
         let "index += 1"
# $index+1 #increment index and plop in letter to filename mechanism index=$index+1 #increment index and plop in letter to filename mechanism
         eval wget http://eibd.investors.com/pdfibd/$filename --http-use=$LOGIN --http-passwd=$PASSWORD
      
         if [ $index -ge 26 ];
         then STOPFLAG=1
         fi
      done

   fi
fi


Top
 Profile  
 PostPosted: Fri Sep 05, 2008 11:25 am   

Joined: Tue Apr 01, 2008 10:19 am
Posts: 49
I don't understand... why are you using `eval' for wget?


Top
 Profile  
 PostPosted: Fri Sep 05, 2008 12:09 pm   

Joined: Fri Sep 05, 2008 7:50 am
Posts: 3
Location: Graduate School
I was using eval I suppose out of ignorance. I thought that without the 'eval' it wouldn't execute the command.
I tested the longer script without the eval command and the same error (no such file or directory) occurs.
Eval also worked for the smaller script so I figured if it ain't broke don't fix it.


Last edited by NicKawasaki on Fri Sep 05, 2008 12:11 pm, edited 1 time in total.

Top
 Profile  
 PostPosted: Fri Sep 05, 2008 12:10 pm   
User avatar

Joined: Sun Apr 13, 2008 4:05 am
Posts: 37
Location: /dev/random
Daenyth wrote:
I don't understand... why are you using `eval' for wget?


maybe its a tclsh script :D


Top
 Profile  
 PostPosted: Fri Sep 05, 2008 12:20 pm   
User avatar

Joined: Sun Apr 13, 2008 4:05 am
Posts: 37
Location: /dev/random
your problem is declaring a "PATH"

when you give
PATH=$2

system path goes to argument and does not look to /usr/bin so it cant find the wget. thats all.

PATH is a system variable, so u have to use any other name for your argument path
for exampls make it
MYPATH=$2 #no error


Top
 Profile  
 PostPosted: Fri Sep 05, 2008 12:24 pm   

Joined: Fri Sep 05, 2008 7:50 am
Posts: 3
Location: Graduate School
Cool. That was it.
I should've realized that PATH was a reserved variable.
Thanks much.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP