I have this shell script and I keep getting strange errors. One of them is needing a do. Another is that config.txt is not found but I have it in the directory with the .sh script.
Here is the error printout:
jmgreen@jdev:~/citigetbash$ sh citiget.sh
: not found 2: clear
CITIGET
config.txt: No such file or directory
citiget.sh: 17: Syntax error: word unexpected (expecting "do")
Here is an LS of the directory:
jmgreen@jdev:~/citigetbash$ ls
citiget.sh config.txt docs
Here is my shell script
#!/bin/bash
clear
strTitle="CITIGET"
echo $strTitle
#=====CONFIGURATION=============================================================
strLocalDir="/home/jmgreen/citigetbash/"
intMode=1
intTry=5
#===============================================================================
#
# ===== Read in all the URLs
strDir=$(pwd)
URLS=$(cat $strLocalDir"config.txt")
echo $URLS
# ===== Get the file
if [ $intMode = 1 ]; then
for u in $URLS;
do
# ===== Get the datestamp ready
ts=$(date +%Y%m%d%H%M%S);
echo "Trying..."$u
wget $u --no-check-certificate -t$intTry -a logfile.txt -O $strLocalDir"downloaded/"$ts".csv";
done
else
for u in $URLS;
do
# ===== Get the datestamp ready
ts=$(date +%Y%m%d%H%M%S);
wget $u -q --no-check-certificate -t$intTry -a logfile.txt -O $strLocalDir"downloaded/"$ts".csv";
done
fi
# ===== Clear Screen?
if [ $intMode = 1 ]; then
clear
fi
echo "===== DONE ====="
exit
First, replace
cat $strLocalDir"config.txt"bycat "${strLocalDir}config.txt".Then, check what does config.txt contains ? This will be moved to the $URLS variable, maybe it s not well formed.
When you have such problems try to insert debug statements, like print. Test the value of your variables each time they’re needed, you’ll know more precisely where does the code fail.