Monday, December 14, 2009

Adding a startup script that always runs at boot time

You have a script that you need to run everytime your system boots? say, for example you need to dial up to connect to internet. Its very simple and straight forward:-

Write a script and add it to your /etc/init.d/ directory, say your script's name is wvdial.sh

$ mv wvdial.sh /etc/init.d/

$ update-rc.d wvdial.sh defaults

that's all... now boot your system and tada... no more typing in commands on the terminal after boot to do those daily bootup tasks!

Thursday, October 1, 2009

Backup your code using a shell script

There are a number of version control system such as CVS and svn that help you do a lot of stuff one of which is to have a backup of your code so that you can revert back just in case you screw up. But it's not really worth it if you're working alone on that code and its not too many a files. For example you're doing your coding assignment that won't last for more than 15 days. And yes, as per the lab instructions you have to do the coding all by yourself. In such cases, its good to have a script handy that can create a backup of your code and name it appropriately (say today's date) and store it in a backup directory.

I created such a script for my day to day assignments and am sharing with you all.

------------------------
Filename: backup.sh
------------------------

#!/bin/sh

FILENAME=`date +%y_%m_%d.tar`;
echo $FILENAME;

tar -cvvf $FILENAME code/;
mv $FILENAME backup/;

----------------------

This script creates a tar archive of the code directory, names it today's date and stores it in the backup directory.

A sample run of the code gives the following output and a tar archive by the name 09_10_02.tar is added to the backup directory.

-----------------------------------------------------------

amit@texens:~/btp/src$ sh backup.sh
09_10_02.tar
drwxr-xr-x amit/amit 0 2009-10-02 01:39 code/
-rwx------ amit/amit 10077 2009-10-02 01:39 code/main.c
-rw-r--r-- amit/amit 93 2009-10-02 00:04 code/Makefile
-rwxr-xr-x amit/amit 18344 2009-10-02 01:38 code/main


amit@texens:~/btp/src$ ls backup
09_10_02.tar

----------------------------------------------------------

NOTE: one may change the date format to reflect the current time in addition to the date if several backups are made in a single day.

Thursday, September 24, 2009

Dara Recovery from a partition


Ever formatter a partition by mistake, and ended up losing all your essential data? Realized that it was pretty stupid not to backup your favorite pictures, data from your seniors project and about a 100 other scenarios.
I came across a similar situation a week back, what was worse that i lost all my pictures about 20 GB. I had no backup of about 10 GB of them... I had formatter a 200 GB partition while playing with the partition manager.

I tried a couple of softwares including Get Data Back, Recover My Files etc. But none of them helped much. They were unable to build the exact directory structure of my partition. What complicated the matters was the fact that the data to be recovered was very huge in size. We're talking about a partition of about 200 GB.
I came across a utility known as PhotoRec, it was easy to use and in less that 8 hours, it was able to recover most of the data. But it renamed all the files and the directory structure was lost. When you're dealing with pictures, its not much of a problem as you can use the properties of a picture to know the creation date etc. Using a script, one can regroup them and place them into the directories accordingly. But this becomes a huge problem when you're dealing with text files.... and alot of them. All the files from my ongoing seniors project were lost - most of them being C files. I was in total chaos until I found out EASEUS Data Recovery Professional, I used this software to recover all the data. What really impressed me was the fact that the directory structure was preserved with cent percent accuracy. I got all my project files back. It has a demo wizard available for free. But the professional one comes at a price. But the price is nothing when your seniors project is at stake.


THINGS TO KEEP IN MIND WHILE DOING DATA RECOVERY:

* The moment you realize that you formatted a partition by mistake, stop writing on that disk. If it is an external partition, DO NOT MOUNT that partition.
* It is always advisable to make an image of the formatted partition so that in case somethings goes wrong while the data recovery process, you can always be assured that you have a backup. Most of the data recovery programs use a read only permission on the partition, but still it is advisable to have a backup to be on the safer side.

And last, Learn from other people's mistakes... always always always backup your essential data...!

Thursday, July 30, 2009

Redirecting Output from Terminal to a file

Today, I was trying to get a scheduler simulator up and running. The source code had a Makefile which was doing quite some job. I tried to do a make only to end up with a lotta errors. The list of errors was so long that the terminal didn't show up the entire error by scrolling up. I tried to redirect it to a text file using

$ make | tee filename.txt


But, instead of getting the errors, what I got was the entire make command after getting proccessed. I was interested in the errors rather than what the make command was.
I used this useful feature called script. All you gotta do is run the script command before you start.

$ script


You'll get the prompt

$ Script started, file is typescript


This is the system's way of telling that the system is recording everything going on the terminal
Once you're done recording, just type the exit command

$ exit


And tada... its done, the terminal tells you

$ Script done, file is typescript


Everything goes into the file 'typescripit' which is created into the current directory.
For details checkout the manpages for script

$ man script

Friday, September 26, 2008

welcome to google blogger...

This is yet another proof of google taking over the world... Well, I do have a blog by some other provider, but then Why not have one on google blogger. anyways this is just a stab post to check if all things and my new theme is working or not. Sorry to disappoint you, seems you'll have to wait a few more hours to read my first post. Keep patience...!