LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Parsing delimited file and variable scripting. (https://www.linuxquestions.org/questions/linux-general-1/parsing-delimited-file-and-variable-scripting-834048/)

mmcc0912 09-23-2010 12:29 PM

Parsing delimited file and variable scripting.
 
I did some searches and after a few hours was able to get what I needed. What I didn't find was a fully encompased means of what I'm used to in the windows world in working with delimted files. Hopefully this is helpful to others and if there is something better or leaner way, even better.

We have an issue where managing printers, just viewing on RHEL w/ sys-conf-prtr we lose any number of, up to ~30 printers from lpadmin. Rather than stare and compare to find the missing ones, I wanted to make an intuitive script. This is what I came up with.

Code:

#!/bin/sh

while IFS="," read Prntr IP; do
  lpstat -a | grep $Prntr > /dev/null 2>&1
    if test $? != "0"; then
    lpadmin -p $Prntr -u allow:all -v "socket://$IP:9100" -E
    echo "    ..... $Prntr was installed"
    else
    echo "Printer $Prntr is installed"
    fi
done < prntrs.lst | more +2

Here's the output that I get:

Printer test1 is installed
Printer test2 is installed
Printer test3 is installed
Printer test4 is installed
Printer test5 is installed
..... test8 was installed
..... test9 was installed

Thanks all ..

MensaWater 09-24-2010 07:58 AM

Since you solved the issue you should mark it resolved by going to thread tools. That way anyone searching in future can find it.

mmcc0912 09-25-2010 01:45 PM

Right on MensaWater. I also read yesterday that there is a better place for it. Not sure if it can be moved...

Was hoping there would be some additional information on it, I'm new to Linux and going through the learning curve of the different shells and scripting.

Thanks.

GrapefruiTgirl 09-25-2010 01:49 PM

Hi there!

You mean, "a better place for this thread"?

If so, I'd suggest you put in the move request, and have this moved to the /Programming forum, as that would be, in my opinion, the best place for this. If you think another forum would be better, just ask, and a moderator will figure out if it belongs there, or where it would be better located.

To ask for a thread to be moved (or for any other thread/post-related request), just click the REPORT button on your first post in the thread, and send a note to us; we'll take care of it.

Cheers!
Sasha


All times are GMT -5. The time now is 01:04 PM.