Category Archives: Tips

Quickly backup files with this bash script

<img class="alignright size-full wp-image-1256" style="margin: 4px; border: 2px solid black;" alt="Bash script" src="http://www best slimming pills.solarum.com/wp-content/uploads/2013/12/script_icon-sm.jpg” width=”150″ height=”103″ />This 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.

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.

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 Oracle Sun Microsystems T2000 (and similar) ALOM/SC Password Recovery

Use PowerShell To Find Resource Hogs

Tools IconHere’s a quick tidbit for any and all Windows jockeys out there. Need to figure out what is chewing up all of your system resources? Need to do it quickly and easily? Have no fear, Laz and the PowerShell are here. Some of you may know this already, so let those who don’t have some air!

OK, bring up the PowerShell (*note, this is different from the DOS “like” Command Prompt and can usually be installed through Windows Update). Once the PowerShell is open, you can use the ‘ps’ command to get a list of the currently running pr0cesses, but believe you me there are a lot of them and they scroll by all unformatted and hard to read and stuff. All in all you get a bunch of info that is hard to understand!

“So, what are we doing here?” you ask. Well, this is where just like with the ‘ps’ command (and the PowerShell in and of itself too), Windows takes some inspiration from UNIX and not only adds some nifty commands to help wrangle all that information that goes scrolling by, but also the idea of “piping” commands or a more simpler analogy, a way to link commands together. Making them talk to each other, work together and share information like never before. You pipe commands together with the ‘|’ character, and it allows you to run a command and take that output and send it to the next command. You will see this in the final command we will use, take a look:

ps | sort -desc cpu | select -f 20 | ft -a;

So, let’s take a look at what this command or set of commands really, does. First off the ps command gets the current list of processes running on the machine along with certain information about each and every one of them like the ‘Process ID’, the ‘ProcessName’ and the amount of ‘CPU’ time it’s using to name just a few. We then take all of that ‘ps’ data and “pipe” or feed it into the ‘sort’ command, telling sort to … well, sort that information by the ‘CPU’ column in “Descending” order. We then take all that sorted data and use the ‘select’ command to only grab or select the top ’20’ items in the list. Last but not least, we use the ‘ft’ command to “format” the list that we have now, which has been cut down to just the top 20 processes sorted by how much of your CPU they are using starting with the most at the top of the list and then listing the top 20 going down from there.

Ultimately, you run this command just like you see it above and you will get a list of the top processes that looks like this:

PS C:\temp> ps | sort -desc cpu | select -f 20 | ft -a;

Handles NPM(K)   PM(K)   WS(K) VM(M)   CPU(s)   Id ProcessName
------- ------   -----   ----- -----   ------   -- -----------
    197     14    6700   11456    92 1,008.66 2744 AODAssist
    422     15    6272   11572    53   886.27 1112 svchost
   2398   1032  115224   10804   420   863.37 2020 AvastSvc
    827     48  253744  247248   371   641.55 1388 svchost
   1132    106   86252  118472   421   575.07 3596 explorer
    140     69   45028   49456   173   572.51 5012 Everything
    485     47   46612   69228   284   565.83 9608 explorer
   1535     90   33912   49260   433   453.93 1460 svchost
    717     52   29416   27460   124   451.45 1352 svchost
    363     43   41048   11472   176   370.32 4436 svchost
    909     63   94836  129776   726   366.38 6388 dopus
    596     54   24476   26196   248   364.06 5136 avastui
    684     44   22172   23564   241   352.66 1048 svchost
    140     13  119472  113980   183   328.48 6972 vmware-usbarbitrator64
    300     13    9940   14796    64   306.90 6516 WmiPrvSE
    346     31   35176   29280   203   302.42 4688 tlbHost
    225     24 1431016 1339160  1460   263.47 1500 stacsv64
    865     81   27488   36708   149   216.86 1420 svchost
    202     16    7300   15020    96   215.45 1744 WHSTrayApp
    110     10    7144   10368    58   200.74 3252 BitMeterCaptureService

There you go, a nice handy little list of your top offenders! If you keep a PowerShell handy, it can be a very fast way to take a quick look at what’s going on under the hood of your PC. Enjoy!

Cool Tools: Trello – Organize Anything

Trello LogoI have found one of the coolest apps ever for making lists, using a virtual whiteboard, taking and re-arranging notes, outlining and even more stuff I haven’t even figure out yet. It’s an app called ‘Trello‘ and I originally found it on my iPhone for iOS. A few days later I was sitting here at my computer wishing I had it to use on my computer too. Low and behold I went to their website and it’s a web app as well that you can use on any PC/Maz/UNIX/Linux box that has a web browser and an Internet connection! Imagine my surprise!

So, finding that I could use it on my PC and my iPhone (you can use it on Android too, BTW), I just had to share this so everyone could get the benefits of this amazing application too. Now, before you get started, just one thing to share because this irks me when I run into it most of the time, and that is that you will be asked to create an account or log in with Google. Normally, I don’t like this because I figure why do I need to create an account just to use an app, right? Then when I realized I could use it in a browser on my PC the reason became clear. That’s how I can have all of my data in both places. So, YES you can indeed work on the same set of lists, the same data, all the same stuff between your mobile device and your PC at home. Cool, huh?

I highly recommend this app and service, it’s really cool and very productive, it really does a great job of organizing my data. You can create these lists and then move the data elements around by clicking and dragging, and etc. Plus you can drill down to and within each individual element and add more data to each one. It is just amazing what it can do, and therefore what you can do with it. So go try it out … NOW!!

Check out Trello today, you will thank me!

iOS7 is ready to install!

20130919-095455.jpgOK, iOS7 is finally here after much hype and banter from all sides of the park. I went ahead and took the plunge on my iPhone 5 and installed the new OS last night. This is a bit different from my normal way of doings because usually I wait a bit to see how it all shakes out. That way if there are major issues with the launch, or the OS itself, or whatever, I can wait until all the issues are resolved before jumping in.

OK, now I have already been hearing a lot of talk from folk on the ‘net about the new OS. I have been hearing grumblings from iDevice users that installed the upgrade (mostly about the way 7 looks), from Android fanbois that just want to trash anything Apple they can, and even users that like the upgrade and have positive things to say. I’m in the latter category, although you never know, things may change as time goes on, we’ll see.

I am going to continue to learn more about iOS7 (all I can really) and I will report back with everything that I can. From my impressions and advice, to tips and tricks, and whatever else I can think of.

Now, make no mistake, this upgrade is huge, and very different in how things look, how they work and how your device does things and responds to you the user. However, after having spent a few hours with the upgrade, I like it a lot and I plan on going into why that is in more detail in subsequent posts here soon.

For now, if you feel adventurous try it out, otherwise it sure as heck won’t hurt to wait a few days or more to see what things are like after it’s been out for more than one night. Stay tuned, more to come!