4

5 great Perl scripts to keep in your sysadmin toolbox

 1 year ago
source link: https://www.redhat.com/sysadmin/perl-scripts
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

5 great Perl scripts to keep in your sysadmin toolbox

Check out five Perl gems that help you work better, faster.

Posted: January 30, 2023 | %t min read | by Seth Kenlon (Editorial Team, Red Hat)

Image
sea shell with pearl on the sand

Before Python was the ubiquitous multitool of computer programming, Perl was the first choice for hobbyist programmers and lazy sysadmins. Many everyday Linux utilities in use today were written in Perl, so whether you're using Perl as a scripting language or not, you're probably still using Perl programs.

[ Want to test your sysadmin skills? Take a skills assessment today. ]

Perl is easy to overlook because you rarely think about commands in terms of the language they're written in. I sometimes find gems while browsing CPAN (the PyPI of Perl), and here are five of my favorite Perl utilities.

mimetype

A MIME type is a standard way to identify a filesystem entity. On the internet, MIME types help browsers understand what generic icon to assign a file, and they help desktops know what kind of application to use when opening a file.

Unless you use them often, it can be difficult to recall the official MIME type designation for a file type. The Perl script mimetype, in the perl-file-mimeinfo package, provides the quickest and easiest solution:

innotop

You know top, htop, maybe powertop. But if you run databases, then you need to know innotop.

The innotop command monitors a MySQL or MariaDB database, providing performance and I/O statistics (including memory usage and queries processed per second), replication status, a query list, and much more.

You can get innotop from the MariaDB package.

[ Get the MariaDB and MySQL cheat sheet. ]

Linux has plenty of commands to get a profile of your system. There's lsblk for block devices, free for RAM, ip link for network interfaces, and so on. But if you're looking for a unified command to give you just the information you want, you have to try inxi.

The inxi command gives you the information you expect when you want to get a computer's specs:

Nine times out of 10, that's the information you really mean to get, and inxi provides it in a way that's easy to read and easy to copy and paste.

That's not all inxi does, though. There are plenty of extra options available in its man page. For instance, I do a lot of audio work when I can, so seeing a complete list of audio devices is nice:

It's a great tool to have on any system, so download inxi now.

[ Get the guide to installing applications on Linux. ]

parallel

I've written about my love of GNU Parallel before, but it's worth another mention. The parallel command literally means you can do more work, faster, with fewer commands.

And it has two separate entry points: You can use it as the recipient of output sent through a Unix pipe or as a standalone command.

As a piped command, the typical start is the find command:

This command finds all JPEG images in the public_html/images/ folder and converts them, in parallel, to WEBP (and swaps the extension .jpg for .webp in the process).

The standalone version of the command looks a little more mysterious if you're not used to it:

This command uses ffmpeg to convert audio to three different formats.

Parallel is a must-have on any system, and it is available from your software repository.

[ Learn how to get more done at the Linux command line with GNU Parallel. ]

exiftool

It happens all the time. A user uploads a photo containing all kinds of potentially sensitive information in its metadata. Nobody gives it a second thought until somebody thinks to dump the EXIF data on the photo, which provides longitude, latitude, dates, and sometimes even more information about the person who took the picture. You can help protect your users (and yourself) by scrubbing EXIF metadata from photos before those photos are made public. The classic tool for that is the Perl script exiftool.

This command removes all metadata from all photos in the ~/public_html/images directory:

Of course, exiftool is useful for more than just deleting all metadata. You can write new metadata with it or correct metadata that's wrong. For instance, sometimes the EXIF data on a photo asks the photo viewer to rotate the image. When that's not what you want, you can set the Orientation property. There are eight possible values for orientation:

  1. Horizontal (normal)
  2. Mirror horizontal
  3. Rotate 180
  4. Mirror vertical
  5. Mirror horizontal and rotate 270 CW
  6. Rotate 90 CW
  7. Mirror horizontal and rotate 90 CW
  8. Rotate 270 CW

For example:

There are lots of potential properties in EXIF, so it can be difficult to know what values are expected. The exiftool project maintains a friendly conversion table for quick reference.

Perl is a gem

You may not hear as much about Perl as you used to, but that doesn't mean the project's irrelevant. For me, Perl is a great "Bash++" language, with many conventions that feel similar to a C-like or shell scripting language than Python does. Even if you don't intend to write Perl scripts yourself, these five scripts are just the beginning of a collection of amazing utilities you should be using on your system. Try them out!

[ Download now: A sysadmin's guide to Bash scripting. ]


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK