LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-08-2016, 01:13 PM   #1
chris_carr
Member
 
Registered: Oct 2011
Location: Houston Tx
Distribution: RHEL 6
Posts: 57

Rep: Reputation: 0
Bash Script for Adding Printers In RHEL 6.7


Ok,

It has been a while since I wrote a bash script and I need a little help.

I'm charged with migrating printers from our virtual environment to our all-in-one cloud system. I been adding the printers manually via the lpadmin command, but I'm coming up on a huge migration were I have to add about 100 printers, and my wrist hurt just thinking about adding them manually. I have written a script in bash doing a basic for loop, but I can remember how to make the loop cat more than one file.


Code:
#!/bin/bash

Printer_List=printer-list1
Device_List=/root/scripts/printers/deviceURI-list1
PPD_List=ppd-list1

echo
echo

for x in `cat $Printer_List`;do
  echo "Adding Printer For $x"
  lpadmin -p "$x" -E -v "$Device_List" -P "$PPD_List"

  cupsaccept $x
  cupsenable $x
done

echo
Any help would be awesome.

P.S sorry the code format is wrong. I cant remember how you guys make it all pretty.

Last edited by chris_carr; 04-11-2016 at 06:54 AM.
 
Old 04-09-2016, 12:52 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
You can cat more than one file simply by giving multiple arguments to cat command (e.g. cat file1 file2 file3 ...)

Since you're doing a variable you can set the variable equal to multiple files:

Code:
#!/bin/bash

Printer_List="printer-list1 printer-list2 printer-list3"

for x in `cat $Printer_List`;do
echo "Adding Printer For $x"
done
You can put code tags around your code by highlighting it and clicking the # icon for "code". (Or manually type left "[" followed by the word "code" closing with "]" at beginning of your code then doing same thing at end of code except you put in "/code" instead of just "code".
 
Old 04-11-2016, 07:49 AM   #3
chris_carr
Member
 
Registered: Oct 2011
Location: Houston Tx
Distribution: RHEL 6
Posts: 57

Original Poster
Rep: Reputation: 0
What you are saying makes sense, but I can not seem to put it into action. How would I do this with a long lpadmin command?

I dont seem to understand how to make the script assign different variables for the different list.


Code:
lpadmin -p "printer_name" -E -v "device_URL" -P "device_ppd"
 
Old 04-11-2016, 09:06 AM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Ah, I misunderstood. On rereading I see you're trying to get separate values from 3 separate files for different variables in your lpadmin. Assuming you have the same number of lines in each file with each having a single column you can use the "paste" command to join them together as 3 separate columns. You'd then use a while loop in combination with the "read" command that sets variables based on input.


Code:
#!/bin/bash

Printer_List=printer-list1
Device_List=/root/scripts/printers/deviceURI-list1
PPD_List=ppd-list1

echo
echo

paste $Printer_List $Device_list $PPD_List |while read name uri ppd
do
  echo "Adding Printer For $name"
  lpadmin -p "$name" -E -v "$uri" -P "$ppd"

  cupsaccept $name
  cupsenable $name
done

echo
 
Old 04-11-2016, 09:20 AM   #5
chris_carr
Member
 
Registered: Oct 2011
Location: Houston Tx
Distribution: RHEL 6
Posts: 57

Original Poster
Rep: Reputation: 0
YES!!!!

That did the trick. Thank you so much for your help. You are a life saver.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding timestamp to a BASH script thefox Linux - Software 1 11-10-2007 09:29 PM
Adding script file on Bash greatmenon Linux - Software 1 01-21-2006 07:14 AM
adding a rotating - to my bash script Cinematography Programming 3 08-31-2005 01:05 PM
bash script for adding multiple users pilipk01 Linux - Newbie 4 01-12-2004 10:05 PM
Need help adding an IF / ELSE statement to my Bash Script Relix Linux - General 1 08-01-2002 02:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration