Tuesday, 20 August 2013

Shorten your log analysis

Bigger the log file, it will be difficult for anyone to search during analysis, hence wanted to shorten log file based on the Day, Month, and most importantly time(Hour).

I have written script based on the hourly basics, which will retrieve your logs for requested day of the month.

I have tried on Redhat/CentOS.

Script can be found here, Download


echo "Enter the time stamp to search in log files"

read -p "Day: " DAY
read -p "Month[Eg aug..etc]: " MONTH
read -p "Hour[Eg 02, 10..etc]: " HOUR

echo -e "\e[00;31mLogs which occured in mentioned timestamp: $DAY"-"$MONTH"-"$HOUR":00" \e[00m"

if [ $DAY -lt 9 ]
cat $LOGFILE | grep "$HOUR:[0-5][0-9]" | grep -i -n "$MONTH $BLANK$DAY"
cat $LOGFILE | grep "$HOUR:[0-5][0-9]" | grep -i -n "$MONTH $DAY"

Monday, 19 August 2013

Get System Information

This script was made to make my work easy. Let me explain that I needed to pull system information for the servers which I own. Since executing each and every command was an tedious job hence automated in the cron, which will email be once it collects the data. 

Since knowing all information at once was helpful, developed script. I will call this only as pre-release, because I think code must be still revised and should be much more short in lines which could save execution time.

Since I had created Github account long time, I took today to upload the script and sharing for all.

How to create git account from command line, click here
Code can be copy/pasted from the link, getsysinfo.sh

This was tested only in CentOS/Redhat/OpenSUSE.
My first blog to get into Bash via GitHub. 

Thursday, 8 August 2013

Backup/Restore your hard-drive - Linux

I had chosen to backup my hard-drive in-case of any failures.Below are the steps which was made to restore from the hard disk image which was chosen. 

I would here brief you about how could one create an image of an primary disk(i.e here in this case hard disk sda) was backed up to the other remote server.

I have used Power of Clonezilla

as backup and recovery tool.



Here is what it follows for cloning the image of the HDD(sda). Few snaps are omitted as it would be self explanatory.

1. Download an ISO image of CloneZilla and boot clonezilla live media

2. When asked to choose between starting Clonezilla and entering login shell, start clonezilla

3. I am selecting disk-partition as an image to backup.

4. Save an image to remote server.

5. Configure dynamic ip address on the current system. Later configure your IP address, PATH to remote host for saving the disk backup image.

6. Using the provided SSH server information, Clonezilla will use sshfs to mount the remote SSH server's destination directory locally. Press ENTER to continue.

7. Next, you will be asked to choose a cloning mode. Choose "Beginner mode" which accept all default options.

8. In the next screen, decide whether to back up a whole disk or a specific partition in the disk. Here I choose an entire disk.

9. Next, type in the name of a Clonezilla image to be created, and mark the disk to back up

Next, use "check saved image" option if you want to check whether or not an image is restorable after the image is generated.
Finally, Clonezilla will start generating a (compressed) image of a chosen disk drive, and transfer it to a remote SSH server.

11. You will see the following screen after the image has been successfully generated and verified. Press ENTER to continue.

Now you can 
power off the computer, reboot, or start over the same backup procedure for other disk drives/partitions.


Follow the same steps as above, choose "restoredisk" option to restore a whole disk from the image that was created in the past.

Next, choose a Clonezilla image to restore
and the destination disk.

Rest all taken care by Clonezilla.

Successful : I was able to boot to the server after restoration of the partition.