- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
func:nextavailableip wapi in a script
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2018 03:07 PM
When i run this command in command line with $field1 and $field2 define
curl -s -k -u XXX:XXX -H "Content-Type: application/json" -X POST "https://hostname/wapi/v2.7/record:host" -d '{"ipv4addrs":[{"ipv4addr":"func:nextavailableip:'"$field2"'"}],"name":"'$field1'"}' this works and i am able to add a host with next available ip
when i run it in a bash script which reads in a field1 and field2 from a csv
while read field1 field2
do
curl -s -k -u xxx:xxx -H "Content-Type: application/json" -X POST "https://hostname/wapi/v2.7/record:host" -d '{"ipv4addrs":[{"ipv4addr":"func:nextavailableip:'"$field2"'"}],"name":"'$field1'"}'
done < DNS_HOST_record.csv
i get this error
{ "Error": "AdmConProtoError: JSON Decoding: Invalid control character at: line 1 column 62 (char 62)",
"code": "Client.Ibap.Proto.JSONDecoding",
"text": "JSON Decoding: Invalid control character at: line 1 column 62 (char 62)"
}
my DNS_HOST_record.csv file is consist of this file
host123.bladblah.net,192.168.1.0/24
host345.bladblah.net,192.168.1.0/24
not sure what i'm doing wrong here?
Re: func:nextavailableip wapi in a script
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2018 11:14 PM
Hi,
I don't see a problem with your script. I tried it out on my system. It works fine. You can verify how you are passing the arguments to the script. I've attached the screenshots of how I tested it.
Hope this helps,
Krishna
Re: func:nextavailableip wapi in a script
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2018 08:23 AM
So i am not sure why i'm getting the json errors using the same script commands.
Re: func:nextavailableip wapi in a script
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2018 08:43 AM
BTW i have my IFS defined as
IFS=$IFS # Always keep the original IFS!
IFS="," # Now set it to what we want the "read" loop to use
Re: func:nextavailableip wapi in a script
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2018 08:49 AM - edited 11-09-2018 10:20 AM
using the curl command works
putting the same curl command in my bash script fails
#!/bin/bash
# Beginning of common script header section
# First we go ahead and create a log directory where we will log our output..."
clear
logdir="logs"
now=`date '+%Y_%m_%d_at_%H_%M'`
today=`date '+%Y_%m_%d'`
logfile="hostadd_$now.log"
echo "$now HostRecordAdd version 1.0 dated Nov 7, 2018 by Andy Wu"
if [ -d $logdir ]
then
echo "$now Log Directory already exists..." | tee -a $logdir/$logfile
else
mkdir $logdir
fi
touch $logdir/$logfile
echo "$now Beginning script execution...." | tee -a $logdir/$logfile
# End of common script header section
echo | tee -a $logdir/$logfile
#IFS=$IFS # Always keep the original IFS!
#IFS="," # Now set it to what we want the "read" loop to use
echo | tee -a $logdir/$logfile
while read field1 field2
do
curl -s -k -u xxx:xxx -H "Content-Type: application/json" -X POST "https://10.29.12.192/wapi/v2.9/record:host" -d '{"ipv4addrs":[{"ipv4addr":"func:nextavailableip:'"$field2"'"}],"name":"'$field1'"}'
echo
echo $field1
echo $field2
done < DNS_HOST_record.csv
Re: func:nextavailableip wapi in a script
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2018 02:04 PM
found the issue for some reason vi the csv file added some control characters to the file.