4 Replies - 744 Views - Last Post: 10 May 2013 - 04:15 PM Rate Topic: -----

#1 TechnoBear  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 222
  • Joined: 02-November 11

Getting command not found error when running script

Posted 09 May 2013 - 09:14 AM

SOLVED

Ok, so I am getting a command not found error when running a particular script. No other scripts are affected just this one so I am thinking it is something in my writing that I am not seeing. I have everything install and it works fine running from terminal it is just in the running of this script.

Script is:
#!/bin/bash
#
#Script to handle the download, conversion and import of ICC This Week
#
#Create Variables
DATE=`date +%Y%m%d`
FOLDER=NEWS$DATE
PATH=http://www.wazufm.org/upload/$FOLDER
WAZU_HOME=/home/wazu
DROPBOX=$WAZU_HOME/RadioDropBox/Local/ICC\ This\ Week
BACKUP=$WAZU_HOME/RadioBackup/Local/ICC\ This\ Week

#Download Files
cd $DROPBOX
wget http://www.wazufm.org/upload/$FOLDER/TOH_NEWS$DATE-SEG1_of_5.ogg
wget http://www.wazufm.org/upload/$FOLDER/NEWS$DATE-SEG2_of_5.ogg
wget http://www.wazufm.org/upload/$FOLDER/NEWS$DATE-SEG3_of_5.ogg
wget http://www.wazufm.org/upload/$FOLDER/NEWS$DATE-SEG4_of_5.ogg
wget http://www.wazufm.org/upload/$FOLDER/NEWS$DATE-SEG5_of_5.ogg

#Convert to WAV
#oggdec $DROPBOX/*.ogg



The error output is:
./ICCThisWeekDLoad.sh: line 15: wget: command not found
./ICCThisWeekDLoad.sh: line 16: wget: command not found
./ICCThisWeekDLoad.sh: line 17: wget: command not found
./ICCThisWeekDLoad.sh: line 18: wget: command not found
./ICCThisWeekDLoad.sh: line 19: wget: command not found


It does this if I try to do ls in the script and with the oggdec line which is currently commented out.

A little debug info:
wazu@wazu-rivendell:~/rdscripts$ bash -x ./ICCThisWeekDLoad.sh 
++ date +%Y%m%d
+ DATE=20130509
+ FOLDER=NEWS20130509
+ PATH=http://www.wazufm.org/upload/NEWS20130509
+ WAZU_HOME=/home/wazu
+ DROPBOX='/home/wazu/RadioDropBox/Local/ICC This Week'
+ BACKUP='/home/wazu/RadioBackup/Local/ICC This Week'
+ cd /home/wazu/RadioDropBox/Local/ICC This Week
./ICCThisWeekDLoad.sh: line 14: cd: /home/wazu/RadioDropBox/Local/ICC: No such file or directory
+ wget http://www.wazufm.org/upload/NEWS20130509/TOH_NEWS20130509-SEG1_of_5.ogg
./ICCThisWeekDLoad.sh: line 15: wget: command not found
+ wget http://www.wazufm.org/upload/NEWS20130509/NEWS20130509-SEG2_of_5.ogg
./ICCThisWeekDLoad.sh: line 16: wget: command not found
+ wget http://www.wazufm.org/upload/NEWS20130509/NEWS20130509-SEG3_of_5.ogg
./ICCThisWeekDLoad.sh: line 17: wget: command not found
+ wget http://www.wazufm.org/upload/NEWS20130509/NEWS20130509-SEG4_of_5.ogg
./ICCThisWeekDLoad.sh: line 18: wget: command not found
+ wget http://www.wazufm.org/upload/NEWS20130509/NEWS20130509-SEG5_of_5.ogg
./ICCThisWeekDLoad.sh: line 19: wget: command not found


This post has been edited by TechnoBear: 09 May 2013 - 09:21 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Getting command not found error when running script

#2 TechnoBear  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 222
  • Joined: 02-November 11

Re: Getting command not found error when running script

Posted 09 May 2013 - 09:21 AM

SOLVED

I just realised reading through my post that I was setting PATH to be equal to the download path meaning that it was searching for commands at the path I gave. Changed Variable name.
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6064
  • View blog
  • Posts: 23,520
  • Joined: 23-August 08

Re: Getting command not found error when running script

Posted 10 May 2013 - 05:30 AM

Use your variables, and repetitive code means loops!

I think I've improved this some, including error checking.

#!/bin/bash
#
#Script to handle the download, conversion and import of ICC This Week
#
#Create Variables
DATE=`date +%Y%m%d`
FOLDER=NEWS$DATE
PATH=http://www.wazufm.org/upload/$FOLDER
WAZU_HOME=/home/wazu
DROPBOX=$WAZU_HOME/RadioDropBox/Local/ICC\ This\ Week
BACKUP=$WAZU_HOME/RadioBackup/Local/ICC\ This\ Week
FILE_COUNT=5

#Download Files
cd $DROPBOX
FILE_TO_RETRIEVE=$PATH/TOH_$FOLDER-SEG1_of_$FILE_COUNT.ogg
RESULT=0
wget $FILE_TO_RETRIEVE
# Check that wget succeeded
if [[ $? -ne 0 ]]; then 
  echo "Failed retrieving $FILE_TO_RETRIEVE"
  RESULT=1
else
  # If you're using bash 3+, then you should be able to use ranges with {2..5},
  # but if you're using variables you've got to get fancy/unsafe (due to eval),
  # like so:
  # for FILE_NUM in $(eval echo {2..$FILE_COUNT}); do
  for FILE_NUM in $(seq 2 $FILE_COUNT); 
  do
    FILE_TO_RETRIEVE=$PATH/$FOLDER/$FOLDER-SEG$FILE_NUM_of_$FILE_COUNT.ogg
    wget $FILE_TO_RETRIEVE
    if [[ $? -ne 0 ]]; then
      echo "Failed retrieving $FILE_TO_RETRIEVE"
      RESULT=1
      break
    fi
  done
fi

if [[ $RESULT -eq 0 ]]; then
  #Convert to WAV
  #oggdec $DROPBOX/*.ogg
fi

exit $RESULT


Was This Post Helpful? 2
  • +
  • -

#4 TechnoBear  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 222
  • Joined: 02-November 11

Re: Getting command not found error when running script

Posted 10 May 2013 - 08:30 AM

Thank you that does actually look a lot better

What exactly does the $? mean?

This post has been edited by TechnoBear: 10 May 2013 - 08:47 AM

Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6064
  • View blog
  • Posts: 23,520
  • Joined: 23-August 08

Re: Getting command not found error when running script

Posted 10 May 2013 - 04:15 PM

It's an internal bash variable, which is the exit status of the last call, in this case the return value of wget. In general UNIX/Linux programs will return 0 on success.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1