Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I get daily a text file with ip:port, one per line, example:

11.22.33.44:80
22.33.44.55:8080
33.44.55.66:7777

I would like to parse the first ip and port in two different variables, then write them into another file, wait exceution of a program that use these variables, loop this cycle to pass all the ip:port to the file and execute program.

How can I do that?

thank you

share|improve this question

1 Answer 1

up vote 0 down vote accepted
#!/bin/sh

while read line junk
do 
  addr=${line%%:*}
  port=${line##*:}
  ./nuke $addr $port
  retval=$?
  case retval in
    0) echo "$addr $port nuked" >> nuke.log ;;
    *) echo "$addr $port avoid nuke" >> nuke.log ;;
  esac

done < /some/file/with/ipports
share|improve this answer
    
Solved: stackoverflow.com/questions/11428579/… , going anyway to check your solution to learn –  MuZo Jul 11 '12 at 8:56
    
rewrite solution to meet all your conditions :) –  Kondybas Jul 11 '12 at 9:06
    
thank you very much :) –  MuZo Jul 11 '12 at 9:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.