I have a script that makes some curl calls to a list of destinations found in list.txt file using keys found in keys.txt, each call result is saved in a different txt file that starts with the server name +_show_counters. When I run this script manually it runs correctly and give me the right responses from the right servers found in list.txt but when ran by cron the information provided does not correspond to the right server but to another which is 4 positions later in the list.
this is the code:
#!/bin/bash
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/puppetlabs/bin
temp=/local/scripts/shell/checker/temp/
timestamp=$(date +'%Y_%m_%d--%H:%M:%S')
paste $temp"list.txt" $temp"keys.txt" > $temp"combined.txt"
awk '{ printf "https://%s//api/?type=op&cmd=blablabla&key=%s\n", $1, $2}' $temp"combined.txt" > $temp"allCurls.txt"
count=1
for crl in `more +1 ${temp}allCurls.txt`
do
filename=`awk -v count=$count 'NR==count{print $1}' ${temp}list.txt`
filekey=${filename}
filename="$temp${filename}_show_counters.txt"
curl -k $crl > ${filename}
echo curl -k $crl >> $temp"curls_debug.txt"
count=$((count+1))
done
This is the cron content:
0,10,20,30,40,50 * * * * /local/scripts/shell/checker/checker.sh > /dev/null 2>&1
I already tried editing the cron to start with below commands but does not make difference.
SHELL=/bin/bash
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/puppetlabs/bin
I found in /var/spool/mail/ below errors, then all consecutive curls right executed which is then causing the wrong order in the results provided.
curl: (6) Couldn't resolve host '::::::::::::::'
curl: (3) <url> malformed
curl: (6) Couldn't resolve host '::::::::::::::'
So I added the echo curls_debug.txt to the for and found:
curl -k ::::::::::::::
curl -k /local/scripts/shell/checker/temp/allCurls.txt
curl -k ::::::::::::::
This only happens when executed by cron, If I run this script manually then the curls_debug.txt shows the curls in the expected format composed of curl -k https://server_name+command+key since the very first curl and therefore brings right results.
Can any one of you please give me a hand to see what is wrong here and how to fix it?, thanks a lot.