Skip to content

Instantly share code, notes, and snippets.

@Jcpetrucci
Created October 16, 2020 13:15
Show Gist options
  • Save Jcpetrucci/34f23aaa62561cb7507f56ebf6765b93 to your computer and use it in GitHub Desktop.
Save Jcpetrucci/34f23aaa62561cb7507f56ebf6765b93 to your computer and use it in GitHub Desktop.
#!/bin/bash
string_searching="Searching..."
while read -r -p '? ' name; do
printf '%s\r' "$string_searching" >&2
curl --netrc -s -X POST -d 'header=yes' --data-urlencode 'query=SELECT d.name as device_name, SUBSTRING(a.alias_name,1,10) as alias, i.ip_address, d.cpucount as sockets, d.cpucore as cores, d.ram, d.ram_size_type, d.hard_disk_size, d.hard_disk_size_type, REGEXP_REPLACE(SUBSTRING(d.notes,1,100),'"'[\n\r]'"','"' '"','"'g'"') as notes, d.first_added, s.name as subnet from view_device_v1 d left join view_ipaddress_v1 i on i.device_fk = d.device_pk left join view_devicealias_v1 a on a.device_fk = d.device_pk inner join view_subnet_v1 s on i.subnet_fk = s.subnet_pk WHERE LOWER( d.name ) like '"'%${name}%'"' OR LOWER ( a.alias_name ) LIKE '"'%${name}%'"' OR LOWER ( d.notes) LIKE '"'%${name}%'"' order by d.name' 'https://ipam.xxxxxxxxxx.com/services/data/v1.0/query/' 2>&1 | column --table --separator ,
echo
done</proc/self/fd/0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment