Redirect wget output to screen (STDOUT)
Jan 25

wget is a great tool for grabbing web pages from the command line, but one issue is it downloads the file and saves to the local directory.  Some times you just want to see the output of what is retrieved.  To do this, use the following command:

wget -qO- http://www.mywebsite.com/file.htm

Piping Tar over SSH
Oct 25

I recently had the issue where I wanted to Tar/Gzip up a large directory but didn’t have the available space on the server, but I need to get it transfered over to another server.  So I came up with two options.  First, Tar/Gzip it and pipe it over SSH and create the tgz file on the remote host, or just pipe and extract it directly on the other host.

The first option, creating the tgz on the remote host can be accomplished by doing this

cd /my/path
tar czf – . | ssh remoteserver “cat > /new/path/file.tar.gz”

The second option, creating the tgz but extracting the contents directly on the remote host can be accomplished by doing this.

cd /my/path
tar czf – . | ssh remoteserver “cd /remote/path; tar xzf -”

Another thing you can do is if you want a path on a remote server but you want to pull it to the local server and extract it you can run the following

cd /my/path
ssh remote “cd /my/path; tar czf – .” | tar xfz -

What me, reboot? Never
Feb 22

I came across an excellent article the other day which talks about server rebooting.  I’ve followed the same practice for many years.  There are very few cases where you should reboot a server.  From experience I’ve actually seen server end up in a worse state because the server was rebooted.  Lesson, it’s always better to troubleshoot a running server, than to reboot and not be able to get into the operating system.

Fun with WIFI
Dec 1

Do you have people that connect to your WIFI without your permission?  This here’s a great hack to have a little fun with those people.  If someone connects that’s unauthorized, the first hack turns all their images upside-down.  The second hack makes all the images blurry.

Oh the fun I could have if I had spare time.

http://www.ex-parrot.com/pete/upside-down-ternet.html

Find out what version of Ubuntu
Nov 23

I’ve recently had to start using Ubuntu, I’m normally a RedHat/Fedora/CentOS guy.  I’ve been using RedHat or derivatives since 1995,  and while I’ve played a bit with other distro’s, I really dislike any of the Debian derivatives.  Anyway, I’ve been needing to do an audit of a bunch of linux servers and find out what version of Ubuntu they were running.  So here’s how I was able to find out.

On a command line type:

cat /etc/lsb-release

If you’re using the Gnome Desktop:

  1. Go to the Main Menu
  2. Click System, Administration, then select System Monitor
  3. Select the System tab.
  4. The version of Ubuntu will be displayed

Backing up a cPanel account via command line
Aug 27

In the past I’ve needed a way to backup an entire cPanel account on my servers so the following has come in real handy.  Just run the following command from the shell and substitute [username] for the username you want to backup (also remove the []).  At the end of the backup process it will tell you where the backup file is located, usually it’s in the /home/ directory on most servers and is named cpmove-username.tar.gz

/scripts/pkgacct [username]

Excluding files in FIND results
Mar 9

Find is one of my favorite little tools under linux.  It helps me “find” almost anything, I can find files older than a certain date, newer than a certain date, modified on a certain date.  I can find files that have a certain name, or match a part of a name, file extension.  Once I’ve found what I’ve been looking for I can have find do something with those files like delete them or gzip them.

My latest “find” with the find command came about because on one of my JBoss servers I wrote a simple script that looks for log files older than 15 days and deletes them and looks for other log files older than 61 minutes and compresses them with gzip.

#!/bin/bash
LOGS=/usr/local/jboss/server/all/log/
#delete all logs older than 37 days
find $LOGS -mtime +15 | xargs rm -rf
# gzip files last modify at least 1 hour ago
find $LOGS -mmin +61 | xargs gzip

Our JBoss setup automatically writes new logs to server.info.log and server.error.log, then every every hour it renames the INFO and ERROR log to the current date + hour, so server.info.log would be changed to server.info.log.2010-03-09-13 for today at 2pm to roll out the 1pm logs.

The problem I came across in my script was with my server.error.log file.  If an error hasn’t been written to the server.error.log file during that hour, it wasn’t going to rotate an empty error log.  Since the file hadn’t been touched/updated/modified in over 61 minutes, my script came along and gzipped it, at this point JBoss then had a problem because the error log was missing and didn’t create a new one.

So what I needed to do was to find all the files that matched the criteria, but exclude the server.info.log and server.error.log and here is my final script.

#!/bin/bash
LOGS=/usr/local/jboss/server/all/log/
INFOLOG=”server.info.log”
ERRORLOG=”server.error.log”
#delete all logs older than 37 days
find $LOGS -mtime +15 -not -name “$INFOLOG” -not -name “$ERRORLOG” | xargs rm -rf
# gzip files last modify at least 1 hour ago
find $LOGS -mmin +61 -not -name “$INFOLOG” -not -name “$ERRORLOG” | xargs gzip

Some interesting MySQL projects to check out
Feb 11

While working on some MySQL stuff today I came across some interesting projects.  About 2 years ago I attended the Boston MySQL Meetup group which had a guest speaker (Patrick Galbraith) and he spoke about setting up MySQL in a Multi-Master setup.  This is where you have two MySQL database servers and each one is a slave of the other.  Today I came across two projects that look promising, the first is Multi-Master Replication Manager for MySQL (or MMM) and the second is Flipper.

MMM is a set of scripts that perform monitoring/failover and management of MySQL master-master replication.  Flipper is also a set of tools that manage which server in a Multi-Master setup is writable and which is readable by moving IP addresses based on the server’s role.  Both look very promising and hopefully soon I’ll have some free time to play around with them.

Working with Percona’s MySQL and RPM dependency problems
Feb 11

I’ve started using Percona’s version of MySQL 5.1 and have run into a few issues trying to get other tools such as mytop or maatkit to install but have been having problems with RPM dependency’s.  I found the solution on this guy’s blog.  Basically, if you install the MySQL-client-percona, MySQL-percona, MySQL-server-percona, MySQL-shared-percona and Percona-XtraDB, instead of installing MySQL-shared-percona, you should download and force upgrade (rpm -Uvh –force packagename) the MySQL-shared-compat library directly from MySQL.  Just make sure you get the same version from MySQL that you’re using of the Percona MySQL.

A new way to manage files and backups
Feb 7

Do you have multiple computers? Maybe one at work and one at home, or maybe you have two at work. Have you ever said I would love to have a way to keep my documents on multiple computers at the same time and not have to worry about copying the files back and forth. Or maybe you’re just looking for a simple way to backup your files in case of emergencies. Well, you should check out DropBox.

DropBox is a new way to manage your files. First you create an account one their website, then you install a piece of software on all your computers. Then when you add a file into your DropBox on one of your computers, immediately all your other computers download the new file. If you make a change to that document on any of the computers, all the others immediately pickup the change. No more copying your documents to CD/DVD/USB and then over to your other computer. Now all your documents are synchronized immediately.

Here’s another benefit.  If you have multiple computers that have different operating systems, this doesn’t matter.  You can automatically synchronize files between Windows, Mac and Linux too.

Another great feature of DropBox, have you ever accidentally deleted or changed a file and wished that you had a backup copy of it. Well now you do. Now you can recover deleted files or get back previous versions of your documents.

To get started, just go to DropBox and click Download DropBox.

« Previous Entries


Switch to our mobile site