Sto provando a creare un semplice loop / counter script per visualizzare le informazioni sulle stampanti installate. Main the Name, PPD, PPD Version e URI. Ho due problemi ... 1 - il nome non sta arrivando; 2 - il secondo PPD della stampante non è corretto.
Ecco cosa ho:
#!/bin/bash
name=($(/usr/sbin/system_profiler SPPrintersDataType | /usr/bin/awk -F ":" '/Name/{$1="";print $0}' | /usr/bin/sed 's/\ /-,--/g'))
ppd=($(/usr/sbin/system_profiler SPPrintersDataType | /usr/bin/awk -F ":" '/PPD/{$1="";print $0}' | /usr/bin/sed 's/\ /-,--/g'))
ppdversion=($(/usr/sbin/system_profiler SPPrintersDataType | /usr/bin/awk -F ":" '/PPD File Version/{$1="";print $0}' | /usr/bin/sed 's/\ /-,--/g'))
uri=($(/usr/sbin/system_profiler SPPrintersDataType | /usr/bin/awk '/URI/{print $NF}'))
total="${#ppdversion[@]}"
/bin/echo -n "<result>"
for ((counter=0; counter < "$total"; counter++))
{
echo "name: ${name[$counter]}" | /usr/bin/sed 's/-,--/\ /g;s/\ \ //g'
echo "PPD: ${ppd[$counter]}" | /usr/bin/sed 's/-,--/\ /g;s/\ \ //g'
echo "PPD Version: ${ppdversion[$counter]}" | /usr/bin/sed 's/-,--/\ /g;s/\ \ //g'
echo "URI: ${uri[$counter]}"
echo
}
echo "</result>"
L'output:
<result>
name:
PPD: Canon MX410 series
PPD Version: 16.10.0.0
URI: lpd://printer.local
name:
PPD: 16.10.0.0
PPD Version: 16.10.0.0
URI: dnssd://Canon%20MX410%20series%20_1B181C000000._printer._tcp.local./auto
</result>
Grazie.