未加星标

Run PJL Commands From A Shell Script

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二05 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

I love learning obscure and under-utilized things in the tech world; PJL commands fit that bill. You can use PJL commands to get and set printer preferences. This includes getting the page count, setting the serial numbe r, and changing the LCD display message .

I was recently tasked with evaluating our printer usage to determine if we could save money by removing low-usage printers. Like many companies, the majority of our printers were HPs, and we were on a tight budget, so something like Papercut was out of the question. I also wasn’t about to go around to each printer and print out the usage report, nor did I want to enter the Web interface of every printer to manually get this information.

Thankfully, I had already learned how to use PJL commands to set the serial number . During that time, I also learned that you could get information from the printer using the INFO command.

There are two parts to this. First, is a script I made that will accept an IP address as an argument and then use telnet to access the printer, run the PJL command, and then print the output back to the terminal.

The most basic of scripts would look like this:

{ echo -e "\[email protected]";
echo -e @PJL INFO PAGECOUNT;
echo -e "\033%-12345X";
sleep 5; } | telnet ${1} 9100 | sed -e 's/\r$//'

This will run the PJL commands using the escape character when you pass an IP address as a first argument to the script. You could also just replace the ${1} with an IP address, but it’s nice to have it a bit more versatile.

The PJL commands use a special escape character which initiallygave me a big headache until I figured out how to enter it on a Mac. I have learned (thanks to od -bc ) that this is just ASCII code 033 , so I added that into the script to make it more copy/pasteable. So the script:

echo ‘s the commands I want to run pipes them into telnet using the first argument passed to the script which will be the IP address of the printer using port 9100 removes the carriage return characters via sed sleep s for a few seconds to ensure the output is displayed

This will result in some output like this:

Trying 10.20.10.201...
Connected to someprinter.
Escape character is '^]'.
@PJL INFO PAGECOUNT
3733

I ran this once a month and and then compared the page counts to see how often it was being printed to.

If you wanted to reset the counter to zero after each month, you could also do that by adding in this command:

@PJL SET PAGES=0

In my case, it was more important to know the lifetime usage of the printer since most printers had been around for a decade or more.

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

分页:12
转载请注明
本文标题:Run PJL Commands From A Shell Script
本站链接:http://www.codesec.net/view/522748.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(85)