Quickly backup files with this bash script

Bash ScriptThis is something that I use on a regular basis on all of my servers. How many times have you been ready to edit a file and either don’t make a backup copy or make one but by now are real tired of typing out copy one file to another name with a date stamp and blah blah blah. It’s not hard to do, but it gets old quick typing the same thing over and over again, plus you might not always name them the same thing or the same way, so now your backup files have different naming patterns and whatnot.

Don’t worry, I have an easy solution. I created a simple script to backup the file specified and append a time and date stamp to the end of it. I symlink this to the command ‘bu’ in someplace like /usr/bin so it’s always in the path of whatever user I might be (myself, root, backup, whoever?), and then POW, it’s easy to backup files plus they are always named the same way – you just type “bu filename”. Now, if you don’t like the way I name my file copies, feel free to customize this to suit your needs. Also, I currently have the script make the copy right next to the original file, but it would be easy to always copy the files to a backup directory somewhere if you wanted, the possibilities are endless!

OK, on to the script goodness:

#!/bin/bash
 
if [ "$1" == "" ]; then
  echo "No input given, stopping"
  exit
fi
 
YEAR=`date | awk '{print $6}'`
MONTH=`date | awk '{print $2}'`
DAY=`date | awk '{print $3}'`
TIME=`date | awk '{print $4}' | awk -F: '{print $1"-"$2"-"$3}'`
 
echo -n "Backing up the file named $1 ... "
/bin/cp -p $1 $1_${YEAR}.${MONTH}.${DAY}_${TIME} > /tmp/bu_run.log 2>&1
echo "done."

There you have it, a simple file backup script it bash that can save you time and many, many keystrokes. Drop me a comment and let me know what you think, or if you have any suggestions or improvements.

Ch Ch Ch Changes …

Just in case you are wondering what all the colors and new layouts are, I am attempting to find an appropriate theme for the site here, and get it installed and happy. In the process, I will be testing different ones to see what works best and what doesn’t. The theme in use now is a heavily modified version of an off the shelf theme I setup for this site about four years ago. Everyone that is familiar with computers and IT knows that four years is an eternity! So, I thought it was time for a change. Feel free (and please do even!) to hit the contact form and drop me a line telling me what you think about the theme. Whether you like it, hate it, have suggestions or anything else. I’d love to hear your feedback. Thank you!

Tool For Debain and Related Admins

Here is a nifty tool for any Debian administrators out there. Not to mention Ubuntu and other distributions that are based on Debian. It’s a website that lets you point, click and generate a sources.list file for your specific distro. Very handy if you need to create a new sources file. So check it out: http://debgen.simplylinux.ch/

Posted in Uncategorized. Tagged .

Command Line Encryption And Decryption Of Files Made Easy!

Encryption iconHey folks, here’s a fun little tidbit for you. Did you know that you can easily and quickly encrypt and decrypt files using one tiny little command on your super cool Linux or UNIX (Yes, OSX counts) and even Windows command line? For those that haven’t yet heard of it, it’s a command called ‘ccrypt’. Check it out …

First we need to install ccrypt on on your system. For Debian and Ubuntu (which is based on Debian), you can simply use the apt package manager to do this. Remember that you can use the -s flag to test or simulate the install before you actually go through with it in order to make sure there are no surprises waiting for you. Logged in as your un-privileged account, the command would look like this:

sudo apt-get -s install ccrypt

Assuming everything went off as planned, you could then run the real thing:

sudo apt-get install ccrypt

For Redhat (CentOS, and others based on Redhat), they have RPM packages available for download. Along with those they have Debian, Solaris (SPARC and i386), OS/2, SuSE, OpenBSD, and FreeBSD packages as well as pre-compiled binaries for lots of platforms and OS’s, so go crazy people!!

OK, now that you have the package installed, you can have some fun whiling away the afternoon encrypting and decrypting files like mad!

To encrypt a file, run this command:

ccrypt file_name

It’s just that easy.

Naturally, you would replace ‘file_name’ with your real file information. You will be asked to enter a key or password two times. Once complete, the encrypted file will have an extension of ‘.cpt’, and the original un-encrypted file will be replaced by the encrypted file.

To decrypt the file, run the same command the same way and simply add the -d flag.

ccrypt -d file_name

You will be asked for the encryption key or password that you gave it when you encrypted it in the first place, so don’t lose it! As always you can use the ‘–help’ flag or hit up the man pages for more detailed information. Hope you enjoy it!

**ALERT**
**Danger, Will Robinson!**
Cheesy I know, but I hope it’s working. One more time – please note that when you run the command to encrypt a file, the original source file, the un-encrypted file gets replaced by the newly encrypted file. So if you are simply making an encrypted copy for example, the original is gone. If you lose or forget the encryption key or password you will be out of luck. I’m sure it can be cracked by someone, but boy that would be a pain in the arse! So, keep that in mind when you encrypt a file, the file you are encrypting goes bye, bye! It works the same way when un-encrypting, but that’s not as potentially dangerous.

Cool Tools – Take Command: The Best Tool For Command Line Warriors

TCC_screenshot2-bigOK gang, this is a nice one that I have to share with you. If you are a command line junkie like me and are stuck not only in a Windows GUI infested world, but in a world where the Linux distro’s seems to be more and more inclined to head that way too, you might just love this tool. Now, this is Windows only but may run on WINE as well, I haven’t tried it yet but I will do that and report back later.

Anyway, the software is called Take Command, and the beauty of it is that it allows you to run a very sweet console window that is built in, with all kinds of built in variable and functions that makes this thing seem kinda like bash for Windows on crack or something. However, even better is that you can run other console windows of your choosing, right along side the original one all in a nice tabbed interface! What does that mean exactly? You may be asking. Well, check this out: all in one interface I myself have the standard Windows Command Prompt, a BASH shell from Git, a Windows Powershell window, a CYGWIN window, and the customized TCC prompt!!! And I can add more, up to 25 console windows! You just point to the executable to run in that console and away you go, it’s awesome. Now I don’t have to have a bunch of separate windows open, I just have one, that re-sizable, adds copy and paste, and more! One more thing, the way that this software hosts the command console executables (think cmd.exe), it runs it way faster than when running natively! The I/O is awesome! I’m not sure what kind of voodoo the author came up with to make Windows faster but I don’t care, I dig it!

Take Command Screenshot

Click to watch the video

For even more goodness, I mentioned earlier that the app adds more commands (140) and more functions and variables (450) and literally thousands of additional features to the Windows Command Prompt. So, if you are a Windows admin, this tool will really shine for you with their advanced bath file and scripting capabilities, additional features, speed and more. I highly encourage you to watch this video here on the left, it’s short but gives you a quick rundown of the high points of this software. It can do so much and has so much in it, I cannot possible talk about it all.

Now for the bad side, and that is that the tool is expensive, it’s not cheap. We are talking about $99.95 for a license, which isn’t the end of the world but it can be a lot for a sysadmin’s budget. However, it is worth it, and further more, if you are patient, you can find a good deal on it at Bits du Jour. If my memory serves me correctly, I think got my copy for about half price. All in all though, like I said, if you are a command like junkie or warrior, this tool will not only save you time and effort, it will look way cool in your kit too! I use this tool every day and I love it.

One last this, this little gem of a tool will be listed along with all of the other Cool Tools in the list, so when you are done checking this tool out, why don’t you go see the list and check out the rest of the Cool Tools!

*As usual, I want to remind everyone that I am not affiliated with jpsoftware in any way and I get nothing from recommending this or if you buy it, I am telling you about this because I like it, and I think it will be beneficial to other IT warriors out there like me!

Oracle Sun Microsystems T2000 (and similar) ALOM/SC Password Recovery

ServerSo today, I am working on a nice little Sun Microsystems T2000 server. It was purchased used by my customer and I am setting it up. Right away I ran into a snag, naturally, because I didn’t have the ALOM (Advanced Lights Out Management) or SC (System Controller) password for this machine go to this web-site. According to the person that sold the server, it was pulled from a working environment, the drives were wiped and it was sent out to be sold. This means that I had no way to get the old password from anyone, therefore I had to get past it myself.

Let me lay it out for you. In this situation you can’t really recover the password or see what it currently is. The only option at this point is to go in and clear out or erase the ALOM NVRAM so that you can then get access and setup a new password. In order to do this, you will need to connect your laptop to the serial management port. You can do this with a laptop or PC or whatever but for the sake of this article I am going to just use laptop. You will also need access to the power cords, because you are going to have to physically cut the power to the server to get started. OK, ready? Got everything in order? OK, let’s begin. Continue reading