Monday, June 11, 2012

How to format date for display or to use in a shell script

SkyHi @ Monday, June 11, 2012
#!/bin/sh
echo "[potato2/check_relay] $HOSTNAME - `date` " > /tmp/.check_relay.txt
grep 'check_relay' /var/www/Sendmaillog/maillog |grep "`date "+%b %d"`"| awk '{print $7}'|sort | uniq -c |sort -nr >> /tmp/.check_relay.txt
head -500 /tmp/.check_relay.txt  > /tmp/.check_relay.txt

mail -s "[potato/check_relay] $HOSTNAME - `date`" admin@example.com < /tmp/.check_relay.txt



Q. How do I format date to display on screen on for my scripts as per my requirements?
A. You need to use standard date command to format date or time for output or to use in a shell script.
Syntax to specify format
date +FORMAT

Task: Display date in mm-dd-yy format

Type the command as follows:
$ date +"%m-%d-%y"
Output:
02-27-07
Turn on 4 digit year display:
$ date +"%m-%d-%Y"
Just display date as mm/dd/yy format:
$ date +"%D"

Task: Display time only

Type the command as follows:
$ date +"%T"
Output:
19:55:04
Display locale’s 12-hour clock time
$ date +"%r"
Output:
07:56:05 PM
Display time in HH:MM format:
$ date +"%H-%M"

How do I save time/date format to a variable?

Simply type command as follows at a shell prompt:
$ NOW=$(date +"%m-%d-%Y")
To display a variable use echo / printf command:
$ echo $NOW
Sample shell script:
#!/bin/bash
NOW=$(date +"%m-%d-%Y")
FILE="backup.$NOW.tar.gz"
# rest of script

Complete list of FORMAT control characters supported by date command

FORMAT controls the output.It can be the combination of any one of the following:

%%

a literal %
%a

locale's abbreviated weekday name (e.g., Sun)
%A
locale's full weekday name (e.g., Sunday)
%b

locale's abbreviated month name (e.g., Jan)
%B

locale's full month name (e.g., January)
%c

locale's date and time (e.g., Thu Mar 3 23:05:25 2005)
%C

century; like %Y, except omit last two digits (e.g., 21)
%d

day of month (e.g, 01)
%D
date; same as %m/%d/%y
%e

day of month, space padded; same as %_d
%F

full date; same as %Y-%m-%d
%g

last two digits of year of ISO week number (see %G)
%G

year of ISO week number (see %V); normally useful only with %V
%h

same as %b
%H
hour (00..23)
%I

hour (01..12)
%j

day of year (001..366)
%k

hour ( 0..23)
%l

hour ( 1..12)
%m

month (01..12)
%M
minute (00..59)
%n

a newline
%N

nanoseconds (000000000..999999999)
%p

locale's equivalent of either AM or PM; blank if not known
%P

like %p, but lower case
%r

locale's 12-hour clock time (e.g., 11:11:04 PM)
%R
24-hour hour and minute; same as %H:%M
%s

seconds since 1970-01-01 00:00:00 UTC
%S

second (00..60)
%t

a tab
%T

time; same as %H:%M:%S
%u

day of week (1..7); 1 is Monday
%U
week number of year, with Sunday as first day of week (00..53)
%V

ISO week number, with Monday as first day of week (01..53)
%w

day of week (0..6); 0 is Sunday
%W

week number of year, with Monday as first day of week (00..53)
%x

locale's date representation (e.g., 12/31/99)
%X

locale's time representation (e.g., 23:13:48)
%y
last two digits of year (00..99)
%Y

year
%z

+hhmm numeric timezone (e.g., -0400)
%:z

+hh:mm numeric timezone (e.g., -04:00)
%::z

+hh:mm:ss numeric time zone (e.g., -04:00:00)
%:::z

numeric time zone with : to necessary precision (e.g., -04, +05:30)
%Z

alphabetic time zone abbreviation (e.g., EDT)

See also:


REFERENCES

Wednesday, June 6, 2012

Backup your Outlook Express Data: Step by Step..

SkyHi @ Wednesday, June 06, 2012

Outlook express data consists of the several parts.

  • Email messages
  • Account settings
  • Address Book (if used)
  • Mail rules (if any)
  • Passwords

1. Email Messages:

From the Outlook Express menu select Tools | Options | Maintenance and click the StoreFolder button. You see a dialog with the name of the directory that has your mail files. If you look in that directory you find files named after your mail folders and news groups. They all have a .DBX suffix. Outlook Express keeps all messages in these database files. If you make copies of these files regularly, you'll have a safe backup of your OE mail. 
Restore (if necessary): To restore the backup data, just copy it back to the directory. You can selectively restore folders by just copying specific files back. Alternatively, you can use OE's File | Import | Messages feature to import one or more of the backup folders. Email Account Settings
As far as we know, the procedure works for all kind of email: The regular SMTP / POP3 based email, MAPI, IMAP or even the free Hotmail Account, that is built into Outlook. For Hotmail, however, some messages and settings might be stored only at the Hotmail server ( = somewhere at Microsoft !) and not on your local PC.

2. Account settings:

Data about your mail and news accounts are stored in the registry key HKEY_CURRENT_USER\Software\Microsoft\Internet Account Manager. To save this data, start RegEdit and select that key in the left-hand pane. Then from the menu select Registry | Export Registry File. Save the file to a name like "outlook.reg". 
 Restore (if necessary) To restore the account settings, right-click the .REG file and select Merge.
Note: As an alternative, you can save the data one account at a time through Outlook Express: click Tools | Accounts | Export and specify the name of the file to save the settings. Be sure to save this information for every account. 

3. Address Book

Getting the data out of your address book for safekeeping is relatively easy. From the menu select File | Export | Address Book and select the comma separated text file as your output format. Then select the fields you want to export. To make sure you know where the backup is going, give a full path name. To restore the address book or to get your addresses onto a new system, the process is not quite symmetrical. Select File | Import | Other address book and select the text file option again. You'll be given a list of fields to import. Since you're importing a file that was created by Outlook Express, you usually don't need to make any changes here. After that, click your way on through the wizard and you'll get your address book back. 

4. Mail Rules

The mail rules are stored at HKEY_CURRENT_USER\Identities. If you run Regedit and export this entire subkey to a file the same way you did with account settings: from the menu select Registry | Export Registry File. Save the file to a name like "rules.reg". 
Restore (if necessary):  Under the Identities key each subkey has a long number that looks similar to {36753740-2WEE-781D3-89B1-00A0C9900DSA}. So if you have five different identities in Outlook you will have five of these long numbers. Below the numbers are all the settings specific the the identity (signatures, mail rules,...). If you are restoring without reinstall and on the same PC these numbers do not change (as far as we know !) and you can just restore the registry entries by clicking on the reg file.
Moving OE settings to a NEW PC:
If you're moving to a new system or doing a clean install, the {...} numbers are be different and you may have to manually move the entries to the differently numbered entries that are actually being used.
How to do this? This is the method that we use in our office:
1. Export the registry branch on the old PC to a *.reg file. 
2. Transfer this "reg" file to the new PC
3. On the new computer search for the (still empty) settings of your new Outlook Express installation. Once you find, you have the new {...} number!
4. Now, open the transfered*.reg file with a text editor and make a "Search and Replace"
Replace the old {....} value with the NEW {...} that you just located in the registry. 
5. Save this file and then click on it. This will import your old settings in the NEW registry. 

5. Passwords

Outlook Express, along with those of most other Microsoft applications such as Internet Explorer, stores its passwords in .PWL files in your Windows directory. There's a separate file for each username on the system. Backup the files frequently. You can view the content of these files with the FREE "Write All Stored Password" utility from iOpus Software.
6. Recommended Reading:
Last but not least: Microsoft official information on this topic can be found in the following knowledge base articles:

REFERENCES

How To: Transfer your PuTTY settings between computers

SkyHi @ Wednesday, June 06, 2012
PuTTY is tops on the short list of applications I install first on any Windows machine. Over the years I've used PuTTY, I've installed it on a huge number of computers but I've always had one complaint;There isn't a configuration file I can backup or move to a new machine

Getting all the little comfort settings correct for each SSH connection can be a pain. The third time you set emulation, keys, encryption type, etc. for each machine you regularly access, you lose patience. The fifth time you find yourself re-entering settings you might do what I did, find a better way. 

Moving PuTTy settings between computers is an easy task once you know what's involved. We'll find the registry keys where PuTTy stores its configuration information and export them to a file. We'll then use that file we've made to import our configuration on the target machine. 

Exporting Your PuTTy Configuration

Putty stores its settings in the Windows registry. To save a backup of your Putty settings, you'll need to export this registry key to a file. 

HKEY_CURRENT_USER\Software\SimonTatham

(Simon Tatham is the original developer responsible for PuTTy)

1. Click Start->Run and type "RegEdt32" in the "Open" dialog. Click "Ok"



2. One RegEdt32 starts, you'll be presented with an application which looks something like:


3. Press "Ctrl+F" to bring up the Find dialog. Enter the name of the key, "SimonTratham" in the "Find What" field, and make sure only "Keys" is checked in the "Look At" section of the dialog. Finally, click "Find Next"



4. The search may take a while, reminding us that the Windows Registry is a large and mysterious place where dragons be. Let's use these few seconds to reflect on the fact that you should never, ever, never change things in the registry unless you are absolutely, positively, totally, completely, 100%dead sure that you know exactly what you're doing. When the search completes we'll see the key name for which we're looking.



5. Click File->Export. Give your file an appropriate name like, "putty.reg" and click "Save"


6. We're done! Save the putty.reg file somewhere safe. The file doesn't contain any passwords or actual SSH key values so, it's relatively safe from prying eyes. Still, it does contain your configuration and that kind of data is a private matter.

Importing Your PuTTy Configuration

To import your saved PuTTy configuration on any other Windows computer simply copy your exported registry key, right click on the file and click "Merge"



Windows will ask you for confirmation that you want to import this set of registry values. We know this file is safe, because we created it but, you should never import registry information from an unknown source.


That's all you need to know about moving your PuTTy configuration from one machine to another. This can be really useful information when upgrading to a new PC or, if you're an office IT guy where your users all have a standard list of servers they need to connect via SSH, you can create a reference configuration on once machine and "share" it between every computer in the office. 


REFERENCES

Tuesday, June 5, 2012

How To Clear DNS Cache In Mac OSX Leopard

SkyHi @ Tuesday, June 05, 2012

 flushdns leopard How to Clear DNS Cache in Mac OSX Leopard
DNS request are usually cached, that’s good as it help to speeds up the lookups within the samehost but sometimes we will want to clear the cache so it don’t hold the values that are no longer valid. To clear DNS cache in Mac OSX, we can do it with the help of Terminal.

Mac OSX 10.4 And Below

  1. lookupd -flushcache  

Mac OSX 10.5 And Above

However a Mac OSX 10.5 Leopard user will tell you this command will no longer work. In Mac OSX Leopard a new command has been used to replace flushcache. To clear DNS cache in Leopard, use the following command:
  1. dscacheutil -flushcache  




REFERENCES
http://www.hongkiat.com/blog/how-to-clear-dns-cache-in-mac-osx-leopard/

wireless isolation

SkyHi @ Tuesday, June 05, 2012
Enable Wireless Isolation If checked, the wireless client under this SSID can only access internet and it can‘t access other wireless clients even under the same SSID, Ethernet clients or this device. Other clients can‘t access the wireless client, either.

Monday, June 4, 2012

Five Best Android ROMs

SkyHi @ Monday, June 04, 2012

Whether you’re looking to upgrade an Android device forsaken by its manufacturer or you just want more control over the phone or tablet you own, a new ROM is often the way to go. Rooting your phone is the first step, but a new ROM will give you a completely new mobile OS. This week we’re going to look at five of the best Android ROMs.
Photo by Peter Kirn.
It’s important to note that not every ROM is available for every device, and different ROMs are aimed at different audiences — some of them are designed to upgrade the OS, and others are lean and mean installs to speed up your phone. Whichever you choose, you’ll have to make sure your device is supported by the developers behind the ROM before installing.

CyanogenMod

CyanogenMod is arguably one of the most installed Android ROMs in the world. It offers lots of great features, it’s available for more devices than most other ROMs of its type, and it has a level of polish and support that makes it easy to fall in love with.
There are builds of CyanogenMod for Android phones and tablets, and slowly but surely the developers behind CyanogenMod are rolling out Ice Cream Sandwich versions for devices whose manufacturers have given up on upgrading the device entirely. As well, CyanogenMod includes features you won’t find in stock Android, like support for OpenVPN and downloadable themes, plus more privacy tools. You can find a list ofsupported devices here.

Android Open Kang Project (AOKP)

The Android Open Kang Project (AOKP) is a relative newcomer compared to many of the other popular ROMs already available, but it’s rapidly growing in popularity. It offers many of the features that CyanogenMod does, and at first blush you may mistake one for the other. But as soon as you start looking at the options and add-ons, you’ll see the differences. AOKP has earned high marks for add-ons and tools that you can’t get in CM, centralised control over ROM options and more overall customisation options than CM. At the same time, its development community is smaller, and it may not have the same polish and device support that CyanogenMod has. Still, it’s super-fast, it’s stable and definitely worth a look. You can find a list of all supported devices here.

MIUI

MIUI struck us with how beautiful the user interface was and how elegant it made Android look and feel. It’s not the most feature-packed or hackable ROM, but it’s definitely one of the most customisable and elegant, and it’s seriously fast. MIUI started life as a modded version of Android localised in China, but fans of the mod have since localised it for dozens of languages and countries. It offers strong theme support, beautiful stock apps, customisable lockscreens, support for GApps and complete root access. You’re not going to get a wealth of niche features here, but you will get a device that’s much easier and more fun to use once you install MIUI. You can find a list of supported devices here.

Slim ICS

If you have a Galaxy Nexus, Nexus S, Samsung Galaxy S or Galaxy S II, Slim ICS may be the ROM for you. Not only will Slim ICS bring your device up to Ice Cream Sandwich, it’s also a super-thin, lightweight installation that’s remarkably easy to install, even though it’s clearly aimed at advanced users. Slim ICS already has GApps rolled in, so you don’t need to install those later. Where other ROMs try to add lots of new features and tweaking options, Slim ICS is designed to trim the fat down to the bare essentials and give you a fast and clean ICS installation. It’s only available for a handful of Samsung devices, and there’s pretty much one developer and a few beta testers behind the scenes, so don’t expect too many feature additions or new devices. However, it is updated weekly and sports a good number of third-party mods.

Liquid Smooth ROMS

Liquid Smooth ROMS are available for multiple devices. While the project started off with the Motorola Droid, Droid 2, Droid X, Droid Incredible and HTC Thunderbolt, it’s also available for the Galaxy Nexus and a few other devices, although you’ll have to poke around the forums a bit to find them. The banner feature of Liquid is that it’s probably one of the fastest ICS ROMs available — faster even than the stock install that comes on the Galaxy Nexus. You don’t sacrifice features for the speed, but the overall size of the ROM is still nice and small, leaving more space for the apps and features you choose to use as opposed to ones forced on you. GApps are baked right in, and the ROM offers theme support so you can customise it to your liking. All in all, if you have a supported device, it’s probably the leanest, meanest ICS ROM you can download.
No honourable mentions this week, but there are well over 60 different ROMs out there, so whatever ROM you settle on, make sure it’s a good match for the features you’re looking for, the device you own and the version of Android you want to run. These may be our top five, but they may not be the best for your specific device, so do your homework!

REFERENCES

Custom ROMs For Android Explained - Here Is Why You Want Them

SkyHi @ Monday, June 04, 2012

Introduction

Ever wondered what the whole Android custom ROM scene was about?
What is all this talk of installing "aftermarket", custom upgrades on your phone?
Who needs it? Why do it? Is it safe?
Don't fret - I'm here to explain - the AndroidPolice Academy is now in session.
By the way, the word ROM means Read OnlyMemory, but has migrated in the modding community to mean an actual custom OS image that you install into the ROM area of your phone.
Also, the word kernel essentially means the heart of the OS - it's the barebones operating system components.

Custom ROMs

stock ROM is the version of the phone's operating system that comes with your phone when you buy it.
custom ROM is a fully standalone version of the OS, including the kernel (which makes everything run), apps, services, etc - everything you need to operate the device, except it's customized by someone in some way.
So what does the "customized" part mean? Since Android is open source, developers are free to take stock ROMs, modify them, strip them of garbage, optimize them, add things, and pretty much do whatever their imagination and skills allow.

Why You Want Custom ROMs

Update Frequency

Using a custom ROM usually results in more frequent updates that fix bugs and introduce new features because the developer behind the ROM doesn't have the same procedures and red tape that the manufacturer+carrier combo does.
  • A quality update can be churned faster because it doesn't involve the bureaucracy of 30 different project managers, 15 vice presidents, and 5 dozen marketing departments.
  • A ROM developer usually gains a loyal community which beta tests his updates in real life situations and provide feedback, or even fixes bugs - that's the beauty of open source software.
  • Oh and did I mention that ROMs are usually free and supported by optional donations? If you can't afford to pay for it, you don't have to.
  • Finally, most custom ROMs out there are updateable over the air (OTA) and without reinstalling anything.
Who doesn't love open source after this?

Better Performance And Efficiency

Custom ROMs are oftentimes faster, more efficient, and use less memory because
  • the developer ripped out useless garbage, such as carrier installed apps or
  • the developer optimized the kernel. For example, an undervolted kernel can provide a much better battery life than the stock one.

Upgrading To A Better/Later Version Of Android

You can upgrade to a version of the OS that has not yet been released for your device, or never will be. This is possible in 2 situations:
  • leaked version of the new ROM showed up online, and the developer got on it like the fat kid chasing an ice cream truck. This was exactly the case with Hero and Android 2.1, allowing me to upgrade from 1.5 weeks (months) before the official version was available and ditch the bogged down and slow stock OS.
  • ROM from another phone was ported by the developer to work on yours. For example, G1 and MyTouch 3G users may never see Android 2.1 officially released on their phones, but Cyanogen, one of the most respected Android developers, was recently able to create a custom ROM running 2.1 for those devices. Oh, what a happy day it was for MT3G and G1 owners.

Ability To Install Apps To The SD Card

Most custom ROMs nowadays come with the ability to install applications to the SD card, calledApps2SD (or A2SD).
This is currently not possible on stock ROMs, even in Android 2.1 and is supposedly on Google's TODO list.
If you have run out of space on your phone (which I have repeatedly on my Hero), Apps2SD is a killer feature to have.

About That Rooting Business…

Don't confuse custom ROMs with rooting - they're completely different.
We have explained rooting and its benefits in an article called Rooting Explained + Top 5 Benefits Of Rooting Your Android Phone.

The Downsides Of Custom ROMs

Of course, there are dangers of using custom ROMs which you should be aware of.

Something Could Go Wrong

First of all, something may go wrong with the flashing process (that's the process of installing the ROM) and leave your phone in a bricked state. The chances of this are pretty low nowadays, and most of the time you can restore it back to normal.
Try to go for the ROM that has been tested by time and has lots of positive feedback.

Clean Wipe

In order to install a custom ROM, you need to perform a clean wipe.
This means you will lose all existing data, so you have to back everything up first. Of course, just for this, we have a straightforward tutorial that shows how to back up and restore your entire phone: [Complete Guide] How To Fully Back Up And Restore Your Android Phone Using Nandroid Backup.

Potential Problems

Custom ROMs could have bugs… but then so do the stock ones.
However, in case you do find a bug, you actually have a 2-way channel of reporting it - post in the ROM forum and you will more than likely get an answer back and your bug acknowledged.
Try doing this to your phone manufacturer and see if you can get past the first level of outsourced monkeys, let alone actual developers.

You May Void Your Warranty

It's possible that custom rooting will void your warranty because you will "break the seal" on the boot loader by installing a custom one which on some phones apparently can't be undone (this includes the Nexus One). Because of that, the manufacturer might be able to tell that the phone has had a custom ROM installed and not honor the warranty, in case you need to use it.
Now, in most cases, the benefits of the custom ROM outweigh the possibility of your warranty being denied. I recommend getting a warranty from your carrier and using that in case anything bad happens (that warranty is usually unconditional and covers things like losses and physical damage).

Getting The Right Custom ROM

New phones and ROMs come out all the time, and the scope of this article doesn't cover individual ROMs - but the general approach to finding one is Googling for "YOUR_PHONE_MODEL ROM" or something similar, optionally including the wanted Android version. Try it out - you'll find what you want.

Conclusion

And there you have it - another tutorial is in the can, as Leo Laporte likes to say.
Have you found it useful or got anything to add? Please share in the comments.

REFERENCES