Nc command works on it's own - but returning port range not valid in bash script

StackOverflow https://stackoverflow.com/questions/20502932

  •  31-08-2022
  •  | 
  •  

Question

So I'm able to retrieve the firmware of a printer and saving it to a doc by typing:

echo '! U1 getvar "appl.name"' | nc -i2 10.67.12.144 5964>doc

However if I try to check a list of printers in a file (IP's) I get 'port range not valid'

for i in `cat $1`
do
echo -n "$i "
echo‘! U1 getvar "appl.name"’ | nc -i2 $1 5964>doc
done

I'm probably doing something silly here but i just cant figure out what the mistake could be?

Was it helpful?

Solution

You can read each line from a file provided as first command-line argument with read in combination with a while-loop. Provided that the file contains an ip address on each line:

while read ip; do
    echo -n "$ip "
    echo '! U1 getvar "appl.name"' | nc -i2 $ip 5964 > doc
done < "$1"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top