Copy to Clipboard in the Command Line Interface (CLI)

Ever wonder how to copy something from the command line into the Mac OS clipboard? If you want to copy/paste a files content (perhaps a log file or a conf file, etc) into the clipboard to use outside of the CLI, you can use the commands pbcopy and pbpaste. Example: I want to copy the contents of my public key to the clipboard (so I can send it to a server admin who will use it in allowing me to access their subversion repository).

All I would need to do is:
cat id_dsa.pub | pbcopy

(cat writes out the content and then it is piped (|) into the clipboard) This comes in handy!

Nano Tip

I have been doing a lot of work recently on a remote server and have needed to use a text editor – so I decided to use the ever-so-easy nano. Problem is – the files I am working on are very long and editing them is not fun. I finally decided to look through the man pages (I am an emacs person myself) and found something that ended up saving me tons of time…”go to line number”. If you are editing a file and know you need to edit something on line 1245, you would type in:

nano +1245 master.css

and it would open the file to line 1245 so you do not need to scroll down. Thank you man pages!

whereis and locate.

A few simple commands to help make your life working with UNIX a little easier:

  • If you are looking for a certain programs, use:whereis. Example. You want to find out where ipfw is located. In the command line type whereis ipfw and whereis will spit out the location (/sbin/ipfw).
  • If you need to find a program or a file and you know what it is called, use:locate. Example. I know I want to uninstall MySQL, and I want to see every file that has mysql in the file path. In the command line, type locate MySQL and locate will spit out every file with MySQL in the file path. (Note, locate is case sensitive).

print file size command.

Earlier today I was asked for the command to show a file size in UNIX and so I thought I would share. There are, of course, a few ways to do this. One great little command to keep handy is:du -h. The du (display utility) will print out the size of a file or directory. The -h will make it “human readable” (put the sizes in Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte). So, next time you need file or directory sizes, use du -h and be done with it!

command line to the rescue…again.

While upgrading a client’s web site to XOOPS 2.0.14 I ran into some issues with the XOOPS 2.0.14 package file (a tar.gz file). Stuffit Expander would only extract a few folders, then report an error and quit. After a few attempts, and all failures, I had to chose to turn to the command line and bingo, no problems! So, if you ever have any issues with Stuffit Expander and need to uncompress a .tar.gz file, the following commands will come in handy:

  • To uncompress a gz file: gunzip file.gz
  • To uncompress a tar file:
    tar [tar options (usually xvf)] file.tar
  • To uncompress a .tar.gz file: tar xzvf file.tar.gz

Questions? Check out the man pages for tar and gunzip.
[tags]XOOPS, gunzip, tar[/tags]

ubuntu 5.10 for PPC.

Well, after some problems downloading the 3.3GB image of Fedora Core 5 and then my PowerBook not recognizing the DVD media (no, I was not about to re-download all five install CD images and burn them to CD…this is not 1993 again with installer floppies everywhere…and I did not have any other DVD media on hand), I decided to try a different flavor of Linux: Ubuntu. A few people that I I have been talking to recently either prefer Ubuntu, or have recently tried it, like Tim. Since the install image is only 644.5MB, I decided it might be the time to try it out.

From the very beginning, I was impressed. I first had problems with my install because of a CD error, but to my delight, the Ubuntu installer gav eme an option to set up a web server with a click of a button which served all the installation log files so I could look at them and find the problem. When I got home, I burned another copy and while my Comcast connection was out (TV and internet!) I installed and configured Ubuntu with ease.

What I really like so far about Ubuntu:

  • small install (one CD worth)
  • Ubuntu recognized all my hardware without me having to hack anything!
  • the ability to run Ubuntu from a CD (live CD)
  • awesome documentation in the help menu…the “Tips and Tricks” rock, and answered most of my questions
  • the “Snaptic Package Manager” which easily allows you to install packages
  • after installing packages with the “Snaptic Package Manager”, the new applications are put in appropriate menus, etc!
  • the great little sounds I get when clicking on buttons and icons 😉

So far, I am extremely happy with Ubuntu and look forward to using it more and more. It is plenty fast and if all goes well, I may see how it runs on my Apple cube so I can get that back into play. As of now…this is, by far, my favorite flavor of Linux I have played with (Yellow Dog, Mandrake (Mandriva), Redhat, and Fedora FC3, FC4). If you are looking to run Linux, give Ubuntu some attention – it gets the Jappler stamp of approval!

PS. Happy 5th birthday to Mac OS X today. Five years ago, Mac OS X 10.0 was released!
[tags]Fedora Core 5 PPC, Ubuntu PPC, Snaptic Package Manager[/tags]

print out certain line numbers with sed.

It has been a year now since I completed my UNIX/Linux certification training and every once and awhile I think about my friend Perl, but I really enjoy helping others with some simple needs. Ben (yeah, I got him using WordPress too ;)) aked me a great recently:

Question: If i have a huge log text fie and i want to pull a range of lines out of the middle, how can I easily do this?

Answer: sed -n '3,6 p' /var/log/httpd/error_log

Answer broken down:

  • sed is the UNIX tool I chose for this.
  • -n is used so that sed does not print out more than what I need.
  • '3,6 p'indicates that I want lines 3-6 of the log file to print out (in the command line) and the p is used for: “If the substitution was made, then print the new pattern space.”
  • /var/log/httpd/error_log specifies the log file that I need to extract data from

Hope this comes in handy!
[tags] sed [/tags]

Nagios Updated

Hi. I spent my exciting day with my old friend Nagios. Due to a few issues, I had to move my Nagios install to a new server, and while I had the time to move it, I also decided it was time to tweak it some. I wanted to point out that Nagios was updated to version 1.3 (change log). No major changes, but enough to upgrade.
Missed my Nagios articles?

Ps, the upgrade was a piece of cake. No issues (for once).
[tags]Nagios[/tags]

System Monitoring with Nagios – Part 4 of 4

nagios I have decided to write a four part article on the benefits of using Nagios. The first article focused on why I chose Nagios/what it offers. The second article focused on installing Nagios on Mac OS X. The third article focused on configuring Nagios. This fourth article will focus on improving the Nagios interface and further customizing it.

Customizing Nagios…the fun continues.
Run Nagios at Boot with an Init Script: There is a great article on how to create a StartUpItem for Mac OS X. Scroll all the way to the bottom and follow the instructions.

Adding Icons: If you know me, you also know I need to work with a good interface. Nagios…leaves something to be desired, but you can do some little things to make it look better, like adding icons. Icons? Yeah. I use blue Apple logos for all my Mac OS X Client machines, grey Apple logos for my Mac OS X Server machines, Cisco icons for my networking equip, HP printer icons for my printers, etc. How?

  • Download/create/use icons that come with Nagios. Make sure the icons are located: /usr/local/nagios/images/logos
  • Create a config file: /usr/local/nagios/etc/hostextinfo.cfg (see my working example in article 3). This config file allows you to attach an image, url, notes, etc to each host.
  • Uncomment the extended service information line in the cgi.cfg file – around line 275. (xedtemplate_config_file=/usr/local/nagios/etc/hostextinfo.cfg)

Changing the look of the web interface: When I first saw the “stylesheets” folder in /usr/local/nagios/share I got excited. After taking a look at the stylesheets, I became less than excited. Hundreds of “font-family”, “color”, etc styles is…well, not what I expected. Good news, a few good “find and replace” statements and you are set. I recommend doing the “find and replace” in multiple files all at once. Hopefully in version 2 of Nagios, they will go to using one stylesheet that controls everything. Please? 😉
[tags]Nagios[/tags]

System Monitoring with Nagios – Part 3 of 4

nagios I have decided to write a four part article on the benefits of using Nagios. The first article focused on why I chose Nagios/what it offers. The second article focused on installing Nagios on Mac OS X. This third article will focuses on configuring Nagios. The fourth article will focus on improving the Nagios interface and further customizing it.

Configuring Nagios…let the fun begin! With version 1.2 of Nagios, there are multiple files by default located in /usr/local/nagios/etc/:

  • cgi.cfg This file is used to define the settings for the nagios’ CGIs. All of your basic CGI paths, authentication, commands are in this file. cgi.cfg help more cgi.cfg help
  • checkcommands.cfg This file is used to define some basic commands you can use to check your systems with such as “check smtp”, “check ftp”,etc.
  • contactgroups.cfg This file is used to define information about contact groups. Ex. If you have multiple admins for your network (network admin, web admin, database admin, you can define which admins are in certain groups. (Nice to set up so that the web admins are not notified when the file server goes down, and the network admins are not notified when the web servers go down – assuming the network admin has no responsibility for the web servers)
  • contacts.cfg This file is used to define the contact information for the admins that need to be contacted if/when their servers go down. You can define pager numbers/email addresses/IM accounts, etc in this file.
  • dependencies.cfg This file is used to define information on your network’s dependencies. You can define things in a way so that nagios knows that your web server’s availability is dependent on your database server, and your database server is dependent on your local router, and your local router is dependent on your ISP’s router, etc. You can define both host dependencies and service dependencies here.
  • escalations.cfg This file is used to define information on escalating the known problem to other people/groups. This is handy if you have multiple tiers of IT staff, or if you have a small IT staff and want to make sure someone is notified of the problem. (Ex. Network admin is notified the mail server is down, but does not do anything in x minutes. After x minutes, a page, email, IM, etc can then go to someone else or another group of people.escalations.cfg help
  • hostgroups.cfg This file is used to define all the host groups. Ex. You can group all of your database servers, web servers, printers, network equipment, etc.
  • hosts.cfg This file is used to define all your hosts that you want to monitor. Each host will have an entry with the IP, host name, etc.
  • misccommands.cfg This file is used to define all the commands that will notify the admins (notify by pager, email, et).
  • nagios.cfg This file is used to define the main configuration information. nagios.cfg help
  • resource.cfg
  • services.cfg This file is used to define the actual servers and services you want to monitor. If you monitor several services (http, smtp, smb, etc) on one host, each service will have a listing.
  • timeperiods.cfg This file is used to define timeperiods. You can have varying time periods for different services/hosts. Ex. You can set up a “24×7” time period for all your high availability servers, but use a “work hours” time periods for monitoring/reporting failures for something like your printers.
  • **I also added icons and clickable URLs in another config file called: hostextinfo.cfg

All these files…but what do I do with them? How about some working examples of the cfg files that were changed!