Solarum – Information For Everyone

Archive for the ‘UNIX’ Category

Jan
23

Labeling Hard Drives In Linux

Recently I got another external USB hard drive for backing up data. I plugged it in and everything was great except for one thing. The drive came up with the name (label) that Seagate put on there by default. So I was looking a drive mounted at “/media/FreeAgent Drive”, ugh, that sucks. So, I did a little digging and came across this awesome article that covers the many different ways to label your drive. It was interesting that it all basically comes down to your file system, but this article has most everything covered. Check it out

Jan
21

Tired of removing ^M by hand?

Moving files from Windows to UNIX or Linux (and now MacOSX) can be a pain if during the process you end up with a text file full of EOL characters thanks to how Microsoft terminates lines of text in Windows.  Yep, that’s the little ^M at the end of every line.  Sometimes, no matter how hard you try, you can’t help but get stuck with them.

Here’s a tip for getting rid of them once and for all.  Use the dos2unix command!  Just like it sounds, it converts text files riddled with ^M’s to nice pretty *nix happy files.

By default, the command will open and read your file, and write it back to it’s original name and location.  Minus the ^M beasties.  So you can simply do this to convert a file:

dos2unix filename

Yes, it’s that easy.  There are other options if you want to get fancy, read the man page it’s full of information.  Do a quick Google search and you’ll find lots of resources about it, but chances are it’s already part of your Linux distro.  Other operating systems may be different.  Have fun!

Dec
16

PowerUp Your Shell With Your Profile

How about some neat-o shell tricks for everyone to play with? I figured out some neat things the other day while trying to add some functionality to my shell, specifically through scripts or the profile.  What I found was that the magic is in the profile!

Have you ever wanted to have commands that performed certain functions from quick keystrokes rather than long command lines? Of course you have, that’s why we all set aliases in our profiles like ‘ll’ instead of ‘ls -al’ and the like.  But what if you want or need more functionality than simple command shortening? That’s what I was after, more function in a smaller form.  Some way to pass variables to aliases to get more out of them. Ah, but you can’t pass variables to aliases, so we are stuck right? Wrong, that’s where the functions come in to play.

Read the rest of this entry »

Nov
6

Update to the PERL round function

Mr. Thierry H. was kind enough to post a comment with a nice little mod to the PERL round function I posted a while back. With his addition, you can now specify how many digits to show on the right of the decimal. Pretty neat, check it out.

Sep
20

PERL Tip For Data In Arrays

Recently I was working on a script for log reporting.  You know, one of those handy little guys that send you some info every day helping to make sure you keep up with whatever it is that you don’t want to forget about.  Well, some of the data was in a plain old text file, and there is nothing wrong with that.  It’s easy to simply cat the file and pipe it through mailx or mutt, no fuss, no muss.

Read the rest of this entry »

Aug
19

Rsync R Your Friend

Need to sync some files? Locally or remotely? How about re-thinking an old friend, rsync?

You may be like I was, and have discounted rsync for a long time due to the security risk imposed by running the “r” daemon on your servers. Guess what? You can not only use rsync to sync up local directories on the same server (this can be real handy for backups), but you can also sync from one server to another via SSH rather than the rsync daemon. This would be much like scp, only you can sync whole directory trees.

So. Let’s say you want to sync two local directories, how would you do that? Well, if we are syncing /export/datadir to /export/backupdir it would look something like this:

rsync -aruv /export/datadir/ /export/backupdir/

It’s just that easy. Now, those command line switches, what do they do? Check it out:

a = archive
r = recursive
u = skip files that are newer on the receiving end
v = verbose, tell me what's going on

There is another one that is good when syncing between two separate servers, and that is the “z” switch. This tells rsync to use compression during the file transfer thus saving bandwidth. Let’s see what the above would look like from one server to another, as if you are running the command from the server you are syncing to:

rsync -aruvhz --progress server1:/export/datadir/ /export/backupdir/

There are a couple other options there, did you notice? I have added the “h” which tells rsync to output information in human readable format (GB, MB, K, etc), and the –progress which tells rsync to report exactly that, the progress of each transfer. You can use these with local transfers too, mix and match as you see fit.

Pages

Articles