>
Currently Browsing: Scripts

BASH: Building an Arsenal‎ – Part 1

BASH: Building an Arsenal‎ – Part 1
If you spend much time at all coding or scripting you realize that you often do some of the same things over and over. That’s where functions and libraries come in. Having a library of commonly used functions handy helps speedup the coding process quite a bit. Usually I prefer to use the best tool for the job. That means using Perl, PHP, C, C++, BASH, or any other language suited for the task. However, lately I’ve been using BASH more than usual. Primarily because it’s pretty much guaranteed to be on just about ever, non Windows, system that I touch. Unfortunately, while I have an...
read more

BASH: Discover Port on Switch Used by Device (Part 1)

BASH: Discover Port on Switch Used by Device (Part 1)
Sometimes we have a need to figure out which port, on a network switch, a given device is plugged into. In “Part 1” here we assume we have a single switch on our LAN. “Part 2” will go a little deeper and check multiple switches. Using this script, we can search by hostname, IP address, or MAC address. The MAC address is the key to success so, if searching by hostname or IP address, we need to first find the MAC address. We use the “arp” command to check our arp cache for the MAC address. To ensure the MAC address is in the arp cache, we first “ping” the...
read more

Bash: Convert Filenames to All Lowercase

Bash: Convert Filenames to All Lowercase
For today, a short little script to rename files that have capital letters in the name, to all lower case. Years ago this was a common need when copying files from a DOS based PC to a UNIX computer. That’s not so much an issue these days. However, it is a common problem when migrating a website from an IIS server, or an OS X server, to a Linux server, where case sensitivity all of a sudden becomes a concern.   It skips any files that would overwrite any previously existing files. Really, nothing too fancy here… #!/bin/bash # Shell script to rename files, in the current directory, that...
read more

BASH: Multiplatform Scripting – Where’s that command?

BASH: Multiplatform Scripting – Where’s that command?
Today’s dilema? I Revived an old script and pushed it out to a dozen or so different machines. Not really a big deal, except the script relies on the ‘uname’ command. Sadly, like many other commands, ‘uname’ isn’t always in the same place and I hate to rely on $PATH in scripts. Fortunately the solution is simple. I happen to know that it is likely in one of two places (though I check four). With this in mind a simple set of tests can get things running smoothly. #!/bin/bash if [ -x "/usr/local/bin/uname" ]; then uname="/usr/local/bin/uname"...
read more

Perl: Iterating Through Log Files in a Directory

Perl: Iterating Through Log Files in a Directory
Today I share a Perl snippet to iterate through log files in a specified directory. In this particular case there was a need to parse the log files, ignoring previously compressed files. The file names were in the format of: file.log file.log.1 file.log.2 file.log.3.gz file.log.4.gz … file.log.10.gz Though the file names could go up to *.99, we didn’t know which, if any, would be compressed. Obviously using “*.log” wouldn’t get the *.1 or *.2 files and using “*.log*” picked up the compressed files. The solution was to use “glob” with a couple...
read more