Posted by & filed under Code Tips.

This snippet will let you run the same command using each line from a file as a parameter.

cat filename.txt | while read in; do echo "$in"; done

As written it’ll open up filename.txt and echo out every line. Probably not what you want, so replace echo “$in” with whatever command you want to run. The $in variable is the line it’s pulling out of the file.

What I needed this for was to block a bunch of IP addresses that were hitting honeypot files on a server so instead of echo I was running csf to add the IP.

Leave a Reply

Your email address will not be published. Required fields are marked *