Menu
×
  • Main
  • Home
  • Network Monitoring Software
  • Application Monitoring Software
  • Bandwidth Monitoring Software
  • Syslog Servers
  • TFTP Servers
  • Event Log Analysis Software
  • Help Desk Software
  • IPAM Software
  • Netflow Analyzers and Collectors
  • Network Configuration Management Software
  • VN Manager & Monitoring Software
  • Wake On Lan Tools
  • Info & Contact
  • Contact
  • Terms of Use
  • Privacy Policy
  • Disclaimer
  • Legal
  • © 2016 NetAdminTools.com
    All Rights Reserved

Network Admin Tools

  • Home
  • Monitoring
  • Backup/Recovery
  • GNU/Linux
  • Administration
  • Perl
  • Ruby
  • Database

Reading and Writing Files With Perl

Last Updated: September 27th, 2016 at 4:27 pm Paul Anderson

Review By Paul Anderson / September 27, 2016 — Perl

Here is how you can use perl to read from one file and write to another: open(FILEREAD, “< file.read.name”); open(FILEWRITE, “> file.write.name”); while (<FILEREAD>){ print FILEWRITE; } close FILEWRITE; close FILEREAD; This will assign the file handle FILEREAD to the file file.read.name and start reading it in line by line in the while loop. The […]

Creating Calendars With Perl

Last Updated: September 27th, 2016 at 4:27 pm Paul Anderson

Review By Paul Anderson / September 27, 2016 — Perl

In this article we created archived log files. Well, it would be nice to have a way to grab the daily log files off of an HTML document. Here is a perl script that does this: #!/usr/bin/perl for ($month=1;$month<13;$month++){ system(“cal -1 $month 2003 > calout”); open(CAL, “< calout”); print “<pre>”; while (<CAL>){ $last=$_; if($last=~/[A-Z]/){ if($last=~/\d\d\d\d/){ […]

Grabbing output of system commands with perl

Last Updated: October 3rd, 2016 - Paul Anderson

By Paul Anderson / October 3, 2016 — Perl

I often have to snag the output of system commands and parse them with perl. Well, Urbana turned me on to a method of grabbing the output that is much easier than directing the output of the system command to a file and re-opening the file. Just use a pipe: #!/usr/bin/perl open (PINGTEST, “/bin/ping -c […]

Setting Passive Mode for Perl/CPAN

Last Updated: October 3rd, 2016 - Paul Anderson

By Paul Anderson / October 3, 2016 — Perl

One problem with the default install of the CPAN shell is that if you need passive FTP to get through your firewall, the CPAN shell won’t work. Here is the behavior: . . . Invalid PORT. Retrying. –12:26:05– ftp://ftp.perl.org/pub/CPAN/authors/01mailrc.txt.gz (try: 8) => `-‘ Connecting to ftp.perl.org[192.35.244.50]:21… connected. Logging in as anonymous … Logged in! ==> […]

Archiving Files With Perl

Last Updated: May 11th, 2018 - Paul Anderson

By Paul Anderson / May 11, 2018 — Perl

Agatha had some complaints about her chicken cam. People weren’t seeing enough chicken booty. A quick and easy way to do this is to use Perl: while(6 ne 9){ for($c=1;$c<11;$c++){ system(“scp root\@crackers:/chickenpicture.jpg /home/u-1/chickencam”); system(“scp /home/u-1/chickencam/chickenpicture.jpg root\@signalq.com:/web/path/here/”); system(“scp /home/u-1/chickencam/chickenpicture.jpg root\@signalq.com:/web/path/here/archive/chickenpicture”.$c.”.jpg”); sleep 300; } } This way, the chicken cam cycles through. The only tricky part is […]

Compression of Text With Perl – Part 1

Last Updated: May 11th, 2018 - Paul Anderson

By Paul Anderson / May 11, 2018 — Perl

In this article I show how to use Perl to extract keywords from a text file, create an index of these keywords, and reassemble the text in a simplified way. This will give you compression, as well as control over stored data. I used The Snow Queen with the simplified character set of the Odyssey […]

Compression of Text With Perl – Part 2

Last Updated: October 3rd, 2016 - Paul Anderson

By Paul Anderson / October 3, 2016 — Perl

In this article I showed how to extract keywords from a text file to create an index, and I reassembled the text again from the compressed file. In this article, I render the compressed file with a limited character set. Here is the code: %found = (); %index= (); $i=1; # this will grab 196 […]

Matching Hex Characters With Perl

Last Updated: October 3rd, 2016 - Paul Anderson

By Paul Anderson / October 3, 2016 — Perl

You can match hex characters with \x. Just put \x before the hexadecimal number. For instance, if you wish to replace all backspace characters with nothing, use this: perl -pi -e “s|\x08||g” file.txt

Writing a Simple Filter With Perl

Last Updated: October 3rd, 2016 - Paul Anderson

By Paul Anderson / October 3, 2016 — Perl

One cool thing you can do with perl is write a filter. We often tail various log files, but just want to know about specific bits. If we want to see more, we can look at the actual logs; however, for the purposes of the current activity, we don’t need much information. Say your logs […]

Installing The Net-SNMP Perl Module on Windows

Last Updated: October 3rd, 2016 - Paul Anderson

By Paul Anderson / October 3, 2016 — Perl

There are restrictions on the crypt-des.ppd module that make it a rare beastie to find. When you try and install via ppm: ppm> install net-snmp Error: PPD for ‘Crypt-DES.ppd’ could not be found. After some searching, we did find the module at soulcage.net. The site seems legit, but do your own homework. To add the […]

Sending a Command Via TCP With Perl

Last Updated: October 3rd, 2016 - Paul Anderson

By Paul Anderson / October 3, 2016 — Perl

To send a command via TCP with Perl, you can use IO::Socket::INET: use IO::Socket; my $sock = new IO::Socket::INET ( PeerAddr => ‘localhost’, PeerPort => ‘1001’, Proto => ‘tcp’, ); die “Error: $!\n” unless $sock; print $sock “commandtoexecute\n”; close($sock); This will send the command commandtoexecute to port 1001 on localhost or complain that there is […]

Extracting NT user and group information using Perl.

Last Updated: May 11th, 2018 - Paul Anderson

Review By Paul Anderson / May 11, 2018 — Perl

We need an easy way to gather group and user information from our PDC in a format that will be easy to automate on our Linux box. [Check out nt2linux also. We like the flexibility of scripting our own stuff, but nt2linux might work for you.] Here is a filter we whipped up in perl: […]

Converting File Extension to Lower Case With Perl

Last Updated: October 3rd, 2016 - Paul Anderson

By Paul Anderson / October 3, 2016 — Perl

Let’s say that you have a bunch of references to files that take the format IMGblahx.JPG, but all of the files are actually IMGblahx.jpg. An example file would be named IMG_1807.JPG. To change all of the references to IMGblahx.JPG to IMGblahx.jpg, use this one line perl script: $ perl -pi -e “s|(IMG……)JPG|\$1jpg|g” * Put an […]

Migrating dates to MySQL format

Last Updated: September 27th, 2016 at 4:27 pm Paul Anderson

Review By Paul Anderson / September 27, 2016 — Perl

If you are used to entering dates in the format DDMMYY, or have existing databases in this format, a quick perl script can migrate these for you. MySQL uses the format of YYYYMMDD. Actually, this makes a lot of sense when sorting left to right. The format for Excel spreadsheets (at least default) is this […]

Bashing Perl

Last Updated: September 27th, 2016 at 4:27 pm Paul Anderson

Review By Paul Anderson / September 27, 2016 — Perl

Perl can make quite a useful addition to bash. Typically, sed would be used to massage strings; however, the regular expressions support in perl is more flexible. Say we have a directory with a bunch of files similar to this: [u-1@srv-1 ~/bp]$ ls april04stuff.html april14stf.html jl11stuff.html may12stf.html may13stf.html We decide that we want all files […]

Perl File Tests

Last Updated: September 27th, 2016 at 4:27 pm Paul Anderson

Review By Paul Anderson / September 27, 2016 — Perl

There are quite a few simple file tests you can use while waltzing around your filesystem with perl. Here are a list of tests. Let’s run the test from the command line. To test if a file exists: srv-44 tmp # mkdir -p /tmp/perltest srv-44 tmp # cd /tmp/perltest srv-44 perltest # cat /dev/null > […]

Creating Date/Time Stamps With Perl

Last Updated: September 27th, 2016 at 4:27 pm Paul Anderson

Review By Paul Anderson / September 27, 2016 — Perl

If you wish to use perl to create a date/time stamp, well, there are a few gotchas. We’ll show you one way to navigate the gotchas in this article. See this page for the technical details of the perl localtime function. Interestingly, we will focus on the date format of this very article. 🙂 This […]

Search

Must Read Resources

  • WHITE PAPER
    Network Management Software Buyers Guide
  • WHITE PAPER
    GNS3 Network Emulator Training
  • WHITE PAPER
    Netflow Best Practices
  • WHITE PAPER
    Learn how to Analyze Packet with Deep Analysis
  • WHITE PAPER
    How to Find your Highest Bandwidth Users
Network Admin Tools
Network Admin Tools

Categories

  • Active Directory
  • Administration
  • Backup/Recovery
  • BSD
  • Bugs and Fixes
  • Certification
  • Comparisons
  • Database
  • Desktop
  • DIY
  • Email
  • ERP
  • File/Print
  • GIAGD
  • GNU/Linux
  • GNU/Linux Dictionary
  • Hardware
  • Information Grab Bag
  • Interoperability
  • Monitoring
  • Name Resolution and DNS
  • Network Management Software
  • Network Services
  • Networking
  • Perl
  • REALbasic
  • Remote Control
  • Ruby
  • Security
  • Software
  • Solaris
  • Syslog Servers
  • TFTP Server
  • Uncategorized
  • Web
Network Admin Tools
Network Admin Tools

Information

  • Contact
  • Privacy Policy
  • Terms of Use
  • Disclaimer
  • Legal

About

  • About Us
  • Contribute
  • Staff/Authors

© 2026 Network Admin Tools · Powered by Leanpress