-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddprinter.pl
More file actions
executable file
·39 lines (33 loc) · 1.11 KB
/
addprinter.pl
File metadata and controls
executable file
·39 lines (33 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/perl -w
# Add a printer to cups using lpadmin api
#
# example command:
#
# lpadmin -p aplbl_pro -L "APLBL_PRO" -E -v lpd://172.20.89.71 -m raw
#
# input file is named "printers.txt".
# format of file is ip address of printer, 1 or more blanks or tabs, followed by the printer name.
# example:
#
# 172.20.0.80 testprt1
my $cmd = "which lpadmin";
my $junk = `$cmd`;
if ($?) {
warn "lpadmin note found: $!\n";
}
open(IN,'./printers.txt') or die "printers.conf not found: $!\n";
while(<IN>) {
next if /^\s+$/;
my($ip,$printer) = split;
$cmd = 'lpadmin -p ' . (lc $printer) . ' -L "' . (uc $printer) . '" -E -v lpd://' . $ip . ' -m raw';
# show example commad to create printers - pass no arguments
print "Example command to create printer: " . lc $printer . "\n" if $#ARGV + 1 == 0;
print "$cmd\n" if $#ARGV + 1 == 0;
# run command to create printers - pass any argument
print "Creating printer: " . lc $printer . "\n" if $#ARGV + 1 > 0;
$output = `$cmd` if $#ARGV + 1 > 0;
print "$output\n" if $#ARGV + 1 > 0;
if ($?) {
warn "Error running lpadmin command: $!\n";
}
}