Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

i made this script here, and get the error

IA-exporto.sh: 13: wget: not found

i tried changing the " by ` and mixed all together and rearranged, but it just won't do..

#!/bin/bash
UNAME="maximilian"
PWD="password"
DATE=`date +%Y\-%m\-%d`
DAY=`date +%d`
MONTH=`date +%m`
YEAR=`date +%Y`

PATH="/root/test/IA"

URL="http://www.my-corpo.com/_backend/index.php?date=$YEAR-$MONTH-$DAY&view=csv"
COMMAND="wget --user=$UNAME --password=$PWD $URL -O $PATH-$DATE.csv"
$COMMAND

i even tryed to set before and after every variable a ", so it looks like

COMMAND="wget --user="$UNAME" --password="$PWD" "$URL" -O "$PATH"-"$DATE".csv"

but when i echo $COMMAND it looks very right, in fact, when i copy it from and insert it, it works..

share|improve this question
    
are you running the script via cron? –  Danie Feb 15 '13 at 6:02
add comment

3 Answers 3

up vote 4 down vote accepted

You're overriding the $PATH variable, which determines which directories are searched for executables (like wget):

PATH="/root/test/IA"

So the shell is only looking in /root/test/IA for the wget command. Change your variable name to something else.

share|improve this answer
    
Holy noodlemonster, you finished my workday after 10 hours. Thank you very much! –  zwarag Feb 14 '13 at 18:02
1  
Besides PATH, there are a number of other all-caps variables with special meanings. Using lowercase (or mixed-case) variable names is a good way to avoid problems like this. Also, storing commands in variables before running them can cause a variety of problems -- see BashFAQ #050. –  Gordon Davisson Feb 15 '13 at 3:32
add comment

You probably want to do:

    PATH=/root/test/IA:$PATH

instead of

    PATH=/root/test/IA

In order to preserve your current PATH variable but give the executables in /root/test/IA preference over other similarly named executables in the current PATH.

It is generally considered bad practice to use full paths to executables (i.e. to not use the PATH concept) in scripts, because this destroys the portability of the scripts and more importantly, it prevents you from overriding distribution default executables with your own. For example, most distros install wget in /usr/bin. If you want to install another version of wget in /usr/local/bin or in ~/.bin, without removing the distro default wget, but use your own wget in the script, then you should set PATH=$HOME/bin:/usr/local/bin:$PATH. This use of PATH is a critical feature if you do cross-platform development. In this situation you might have five different gcc toolchains installed. You don't want to have to have five different versions of a compilation script, so you rely on the shell's use of PATH to select the correct toolset.

Note that if you intend to run this script from crontab, you might have to explicitly add directories to the PATH variable because the default cron PATH includes just a few directories, as gregseth explains.

share|improve this answer
add comment

Generally it is considered good practice to use full paths in scripts to not depend on preset search paths.

  1. which wget will tell you the path to wget (probably /usr/bin/wget)
  2. you change COMMAND="wget --user...." to COMMAND="/usr/bin/wget --user...." (or wherever your wget sits)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.