Hi, I have the below requirement.
I have multiple arguments which needs to be passed to curl URL and the code looks something like below.
But it is giving an error . I have attached a file,
Hi, I have the below requirement.
I have multiple arguments which needs to be passed to curl URL and the code looks something like below.
But it is giving an error . I have attached a file,
Hi, I have the below requirement.
I have multiple arguments which needs to be passed to curl URL and the code looks something like below.
But it is giving an error
#!/bin/bash
INPUT=data.csv
URL="https://10.14.76.48:8443/v1"
loglevel_function()
{
echo "----- STARTING THE TESTEXECUTION OF "$1"-"$2"-----------------------------------------------"
status_code1=$(curl --output temp.txt $3 $4 $5 $6/loglevel?loglevel=$7:$8);
if [ "${status_code4}" == 200 ]
echo "------ STARTING THE TEST--------------------------"
then
echo "TEST PASSED"
echo "TEST $1-$2 STARTED" >> TESTPASS.txt
cat temp.txt >> TESTPASS.txt
echo >> TESTPASS.txt
echo "TEST $1-$2 END" >> TESTPASS.txt
echo >> TESTPASS.txt
echo >> TESTPASS.txt
echo >> TESTPASS.txt
echo >> TESTPASS.txt
else
echo "TEST FAILED"
echo "TEST $1-$2 FAILED " >> TESTFAIL.txt
cat temp.txt >> TESTFAIL.txt
echo >> TESTFAIL.txt
echo "TEST END" >> TESTFAIL.txt
echo >> TESTFAIL.txt
echo >> TESTFAIL.txt
echo >> TESTFAIL.txt
echo >> TESTFAIL.txt
fi
echo "----- ENDING THE TESTEXECUTION OF "$1"-"$2"-----------------------------------------------"
}
OLDIFS=$IFS
IFS=','
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read targ1 targ2 targ3 targ4 tmodule tparam
do
loglevelmodule_function $targ1 $targ2 $targ3 $targ4 $targ5 $URL $tmodule $tparam
done < $INPUT
IFS=$OLDIFS
in the csv file I have like this:
TCID,TestName,targ3,targ4,$targ5,tmodule,tparam
1,test-dbdebug,-w %{http_code} -v -k -X,PUT,--cacert /var/opt/BESUEM/certs/mdmca.crt --key /var/opt/BESUEM/certs/client.key --cert /var/opt/BESUEM/certs/client.cert.pem,db,debug
2,test-dbinfo,-w %{http_code} -v -k -X,PUT,--cacert /var/opt/BESUEM/certs/mdmca.crt --key /var/opt/BESUEM/certs/client.key --cert /var/opt/BESUEM/certs/client.cert.pem,db,info
3,test-syncmldebug,-w %{http_code} -v -k -X,PUT,--cacert /var/opt/BESUEM/certs/mdmca.crt --key /var/opt/BESUEM/certs/client.key --cert /var/opt/BESUEM/certs/client.cert.pem,syncml,debug
4,test-syncmlinfo,-w %{http_code} -v -k -X,PUT,--cacert /var/opt/BESUEM/certs/mdmca.crt --key /var/opt/BESUEM/certs/client.key --cert /var/opt/BESUEM/certs/client.cert.pem,db,info
5,test-servedebug,-w %{http_code} -v -k -X,PUT,--cacert /var/opt/BESUEM/certs/mdmca.crt --key /var/opt/BESUEM/certs/client.key --cert /var/opt/BESUEM/certs/client.cert.pem,serve,debug
6,test-serveinfo,-w %{http_code} -v -k -X,PUT,--cacert /var/opt/BESUEM/certs/mdmca.crt --key /var/opt/BESUEM/certs/client.key --cert /var/opt/BESUEM/certs/client.cert.pem,serve,info
[root@localhost certs]# ./myscript.sh
----- STARTING THE TESTEXECUTION OF 1-test-dbdebug-----------------------------------------------
curl: option --cacert /var/opt/BESUEM/certs/mdmca.crt --key /var/opt/BESUEM/certs/client.key --cert /var/opt/BESUEM/certs/client.cert.pem/loglevel?loglevel=db: is unknown
curl: try 'curl --help' or 'curl --manual' for more information
------ STARTING THE TEST--------------------------
TEST PASSED
cat: temp.txt: No such file or directory
#!/bin/bash
cd /var/opt/BESUEM/certs
#cp /home/*.pem /var/opt/BESUEM/certs
#cp /home/*.key /var/opt/BESUEM/certs
rm -rf *.txt
echo "INTIALIZING VARIABLES"
arguments1="-w %{http_code} -v -k -X"
arguments2="GET"
arguments4="PUT"
arguments5="POST"
arguments3="--cacert /var/opt/BESUEM/certs/mdmca.crt --key /var/opt/BESUEM/certs/client.key --cert /var/opt/BESUEM/certs/client.cert.pem"
URL="https://10.14.76.48:8443/v1"
dvalue="ED9A3482A102864A94CC14C5AFBFB619"
param1="debug"
param2="info"
declare -a mod_array
mod_array=( db default serve syncml wns metrics mqpublisher enroll restapi WNS null metrices syncml^%%%30 enr0ll "73 79 6E 63" " " 01110111 )
function loglevelmodule_function()
{
echo "----- STARTING THE TESTEXECUTION OF "$5"-"$6"-----------------------------------------------"
status_code1=$(curl --output temp1.txt $1 $2 $3 $4/loglevel?loglevel=$5:$6);
if [ "${status_code1}" == 200 ]
then
echo "$5"-"$6" "TEST-PASSED"
echo "START OF THE TEST $5-$6" >> TESTPASS.txt
cat temp1.txt >> TESTPASS.txt
echo "END OF THE TEST" >> TESTPASS.txt
echo >> TESTPASS.txt
echo >> TESTPASS.txt
echo >> TESTPASS.txt
echo >> TESTPASS.txt
else
echo "$5"-"$6" "TEST-FAILED"
echo "START OF THE TEST" >> TESTFAIL.txt
cat temp1.txt >> TESTFAIL.txt
echo "END OF THE TEST" >> TESTFAIL.txt
echo >> TESTFAIL.txt
echo >> TESTFAIL.txt
echo >> TESTFAIL.txt
echo >> TESTFAIL.txt
fi
sleep 1
echo "----- ENDING THE TESTEXECUTION OF "$5"-"$6"-----------------------------------------------"
echo ""
echo ""
}
for MODULE in "${mod_array[@]}";
do
loglevelmodule_function "$arguments1" "$arguments4" "$arguments3" "$URL" "$MODULE" "$param1"
loglevelsummary_function "$arguments1" "$arguments2" "$arguments3" "$URL" "$param1"
done
Please help
The first thing to do is to turn debug on.
Either by putting a line
set -x
in the script, or by running your script with
/bin/bash -x ./myscript.sh
Oh thanks, dunnow why it was adding \r at the end of all the rows .
I couls find it in debug mode. There was some space in my csv file i believe, when i removed, it automatically started working
thanks a lot.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.