Linux Command Lines Tips and Tricks

Posted by admin | Posted in System Administration | Posted on 22-11-2009

0

linux_commands_tipsLinux Command Lines Tips and Tricks


Linux Command Lines Tips and Tricks

10 Special Linux Distributions That You Should Know

Posted by admin | Posted in System Administration | Posted on 19-11-2009

0

daniweb

daniweb


10 Special Linux Distributions That You Should Know


http://www.daniweb.com/news/story239006.html#

Setting up Android development platform on Ubuntu Linux 9.04

Posted by admin | Posted in General Programming, System Administration | Posted on 12-05-2009

20

In this post I will go step by step through the setup of your development box for Android and all its goodness. I start with fresh install of the newest and shinest Ubuntu platform 9.04, which by the way on the first look is just great. I’m a happy owner of G1 for a few months and this is the best phone I ever had so why not start writing some software on it!

Step One.

Before installing anything please run the following command (actually 2 commands)

sudo apt-get update && sudo apt-get upgrade

Install Java! You develop on android or not Java is a must on all my machines :)

$ sudo apt-get install sun-java6-jdk

You can now check your java installation by issuing two commands:

$ java -version
$ javac -version

You should be able to see output stating that you have java 6 installed, huuraaayy!

Step Two.

Download and install Android SDK
You can download the latest android SDK from the android development website (developer.android.com), the link to the latest version is here
After your download completes, unzip the file to the directory of your choice. I copy the whole folder into my home directory but the doesn’t really matter.
Open up your favourite text editor (VIM of course) and add the following line at the very bottom of the .bashrc file:

export PATH=${PATH}:/home/kris/android-sdk-linux_x86-1.5_r1/tools

Stepp Three

Download and Install Eclipse

I wish I could go for the easy one here and download the version using apt-get but unfortunately not as the version in repos is 3.2 and ADT plugin requires version 3.3 or higher. You have to download the eclipse for www.eclipse.org and unpack it. Once unpacked its ready to use!

Step Four

Download and install Eclipse plugin
This is instruction from the developer.android.com with one small modification, instead of https use http:

1. Start Eclipse, then select Help > Software Updates….
2. In the dialog that appears, click the Available Software tab.
3. Click Add Site…
4. Enter the Location:

http://dl-ssl.google.com/android/eclipse/

If you have trouble aqcuiring the plugin, try using “http” in the Location URL, instead of “https” (https is preferred for security reasons).

Click OK.
5. Back in the Available Software view, you should see the plugin listed by the URL, with “Developer Tools” nested within it. Select the checkbox next to Developer Tools and click Install…
6. On the subsequent Install window, “Android DDMS” and “Android Development Tools” should both be checked. Click Next.
7. Read and accept the license agreement, then click Finish.
8. Restart Eclipse.

After executing all the steps above you are ready for Android development. The last step in this tutorial is to run example android projects on your linux dev machine.
If you encounter an error saying :

An error occurred during provisioning.
Cannot connect to keystore.
JKS

Please check your java version. If its set to 1.5 than please run the following command:

sudo update-java-alternatives -s java-6-sun

Once you finish installing required plugins, restart your eclipse and go to Window->Preferences->Android and set up a path to your android SDK

Step Five

Check your configuration

If all went fine you can try to develop Hello World application in android. You can find the instruction on the android development site:
http://developer.android.com/guide/tutorials/hello-world.html

More android tutorials to come!
Enjoy!

Backup your MS SQL Server with C#

Posted by admin | Posted in Code Snippets, System Administration | Posted on 08-04-2009

1

Today I will describe some code snippets on how to backup your MS SQL Server database to a ‘.bak’ file using C#. Later on we will zip our .bak file using open source C# zip library as bak files seems to have high compression ratio.
Backing up files require us to connect to the database server and than use of Microsoft.SqlServer.Mangement.Smo objects to create actual backup.

Assuming we have some private fileds ready:

private Server sqlsrv; //initialized when connection succeedes
        private string dbName;
        private string backupFile;
        private string serverName;
        private string sqlUser;
        private string sqlPass;

Lets first create a connection to our database server and initialize our Server type object:

private bool connectToSQLServer()
        {
            try
            {
                ServerConnection serverConn = new ServerConnection(this.serverName);
                // Log in into sqlserver
                serverConn.LoginSecure = false;
                // Give the login username
                serverConn.Login = this.sqlUser;
                // Give the login password
                serverConn.Password = this.sqlPass;
                // create a new sql server object
                sqlsrv = new Server(serverConn);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return false;
            }
            return true;
        }

If all goes fine and we have our Server (sqlsrv) object ready we can start our backup operation:

public bool bakBackup()
        {
            //If the connection returns false return from this method too.
            if (!connectToSQLServer())
                return false;
            try
            {
                // Create a new backup object
                Backup bkpDatabase = new Backup();
                // Set the type to database
                bkpDatabase.Action = BackupActionType.Database;
                // set the database name we want to actually backup
                bkpDatabase.Database = dbName;
                // To get the file from me actual backup create BackupDeviceItem
                BackupDeviceItem bkpDevice = new BackupDeviceItem(this.backupFile, DeviceType.File);
                // add the backup file device to our backup
                bkpDatabase.Devices.Add(bkpDevice);
                // execute the actual backup using Smo
                bkpDatabase.SqlBackup(sqlsrv);
                //verify if the file exist
                if (File.Exists(this.backupFile))
                    return true;
                else
                    return false;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Backup file couldn't be created" + ex.StackTrace);
                return false;
            }
        }

As a side note I would mention that the only two folders I have found on my system where I can actually perform the backup (store tha bak file) is “C:Program FilesMicrosoft SQL ServerMSSQL.3MSSQLBackup” or “C:Program FilesMicrosoft SQL ServerMSSQL.3MSSQLData” folders, this has something to do with permissions setup and I’ll will update this post once I find the solution. You can read my post on stackoverflow regarding this issue.

Assuming that all went ok, lets create a zip file which will compress our bak file to the size more than 2 times smaller than the original bak file.
For file comression I will use great C# library ‘SharpZipLib’ which you can find here.
Before using the snippet below you would have to add a reference to the library in your project.

public static void Zip(string sourceFile, string destinationFile, int BufferSize)
        {
            FileStream fileStreamIn = new FileStream(sourceFile, FileMode.Open, FileAccess.Read);
            FileStream fileStreamOut = new FileStream(destinationFile, FileMode.Create, FileAccess.Write);
            ZipOutputStream zipOutputStream = new ZipOutputStream(fileStreamOut);

            byte[] buffer = new byte[BufferSize];

            ZipEntry entry = new ZipEntry(Path.GetFileName(sourceFile));
            zipOutputStream.PutNextEntry(entry);

            int size;
            do
            {
                size = fileStreamIn.Read(buffer, 0, buffer.Length);
                zipOutputStream.Write(buffer, 0, size);
            } while (size > 0);

            zipOutputStream.Close();
            fileStreamOut.Close();
            fileStreamIn.Close();
        }

Looks pretty easy? Well, actually it is! As a source and destination file arguments provide full path to your file (.bak) as source and (.zip) as destination and you are done.
You can of course change one name to another using simple call:

string zipFileName = fileName.Replace(".bak", ".zip");

Happy coding!

Linux simple backup with FTP

Posted by admin | Posted in Code Snippets, System Administration, Tools | Posted on 06-04-2009

0

This is my first post under new domain ’softwarepassion.com’. I’m planning to blog more from now on as I have loads of new things to blog about :) .
Today I will present you with simple backup shell script I have running on one of my servers. The script is damn easy and all it does is:

  1. remove any earlier backup dirs and create new empty one
  2. create mysql dump for the applications you want to backup
  3. create tar.gz of the entire home directory
  4. create tar.gz of the apache director to preserve settings
  5. create tar.gz of everything I’ve created earlier to place everything in a single file
  6. ftp the file to a backup server

Lets start with the first task. Removing and creating dirs is pretty simple:

rm -Rf /root/temp_bckp
mkdir /root/temp_bckp

Creating mysql backup we can do the easiest using mysqldump utility. The command for this is:

mysqldump --user=your_db_user your_db_name > /root/temp_bckp/your_Db_name.sql --password=your_db_password
echo 'sql dump finished'

Once we got all dumps in place we can start compressing home and apache directories directory:

tar -zcvf /root/temp_bckp/home_bckp.tar.gz /home
echo 'tar of home finished'

tar -zcvf /root/temp_bckp/etcapache.tar.gz /etc/apache2/
echo 'tar of etc/apache finished'

Somwhere at the top of the script we store current date as a variable and we use it to name the final backup archive:

DATEX=`date +%d%m%y`

Final backup archive:

tar -zcvf /root/temp_bckp_$DATKA.tar.gz /root/temp_bckp
echo 'tar of all finished'

When we have all zipped together we are ready to send it over to the ftp backup server, I use ncftp utility which you can easily get on debian based distros using apt-get install ncftp or aptitude install ncftp.

ncftpput -u ftp_user -p ftp_password your-ftp-domain.com . temp_bckp_$DATKA.tar.gz
echo 'ftp finished'

For ftp server I personally use Linode services which are very cheap in the basic package, you can check their offers here

Complete shell script you can download from storage43 under this link
Happy backuping ;)

Install Adobe Flash Player 9 on OpenSolaris 11.2008

Posted by admin | Posted in System Administration | Posted on 08-12-2008

5

I have just installed the newest version of OpenSolaris on my laptop, and now I’m going through the installation of the ‘be-or-not-to-be’ software, I have noticed that the OS 11 has a nice package manager, but I couldn’t find the flash player on it. Here you have a short and easy instructions on how to install flash player on your best of the best opensolaris box:

1. Go to any page where you expect flash contant (e.g www.youtube.com)
2. Click the ‘install flash player’, unfortunatelly it’s not that easy (the reason I’m writing this post) but you can download it on you desktop. If this for some reason doesn’t work (I got some security errors, just use wget to get the file – wget already installed :) ).
3. Un-gzip it.
4. change to root on the console (su -)
5. copy the libflashplayer.so to the /usr/lib/firefox/plugins directory
6. restart the firefox
7. Enjoy flash movies!! :)

Good luck!

OpenSolaris 11.2008 with Windows Vista

Posted by admin | Posted in System Administration | Posted on 08-12-2008

0

I don’t blog much last couple of days (actually months :) ) but this one I just had too. I run into one post on Dzone (link) which was about ZFS time machine in new solaris 11.2008 and I thought that its good time I’ll give it another shot. I had some really bad experiences using solaris/opensolaris in dual boot with Windows Vista and was a bit scared but I’m in SHOCK!!!!! I have a IBM Lenovo R61 laptop, created some additional space using Vista’s partitioner, put the live CD into the cd drive and voila!!!
No problems with wireless (I have to say that it works better than on ubuntu so far), no problems with dual booting either, it was just working straight away, no manual editing of the grub file, nothing, nada, zero, PERFECT!!!
It seems actually much faster (maybe it’s my new laptop who knows).
Guys at Open Solaris — keep up the good work, thanks!

Nice Surprise! – Ubuntu 7.04 with Dell laptop short story!

Posted by admin | Posted in System Administration | Posted on 27-05-2007

1

I have just bought brand new, shiny Dell Inspiron 6400 with Windows Vista installed on it. Well, my Vista experience didn’t last long (about 2 hours) and after I had to restart my laptop several times and answer few questions everytime I wanted to do something (basically anything). I have decided to stop all this and go back to my favorite linux distro. I have left Vista on it as I will need it later for my university work, and decided to create a dual boot machine.
Now very good piece of advice for anyone buying a Dell computer – boot your machine from the recovery disk, install Vista from scratch and get rid of all this software preinstalled, this way you know what is going on.
Vista is quite resistive and wants to have all computer for itself but I had encountered a few very nice surprises.
First of all, Vista has quite nice partitioner. You can partition your disk in very easy and intuitive way.
Secondly and most importantly Ubuntu proved to be great again!
There is no conflict with the boot loaders, the Ubuntu GRUB doesn’t mess up Vista and nicely add it to the grub options. This was really nice as when I always start messing up with GRUB something strange comes out of it ;) this is of course simple lack of understanding things but who has a time for it.
But that is nothing compare to the experience after installation! Everything works perfectly (so far :) ).
All the function buttons, MediaDirect buttos, wireless, memory card reader, nividia graphics (well this one with a little help from automatix), basically EVERYTHING!!!
I understand that this is probably a result of Canonnical and Dell cooperation and I have to say this – Thank you very much!

How to’s: Installing Sun Studio 11 on Ubuntu 7.04 FF

Posted by admin | Posted in System Administration, Tools | Posted on 29-04-2007

6

I have always wanted to dive into C++ world (as a rather lazy kind never did). This is my another attempt. Since FF version of Ubuntu was released few days ago, almost every day I find something new and interesting. As I’m forced to write sometimes a very small C++ application (university commitments) and a couple of months ago I have realized that Sun Studio 11 is freely available, I wanted to give it a try. Unfortunately never did, that’s because somehow I couldn’t run it under Ubuntu (sometimes you have to choose, comparing the amount of work you have to do to actually make it work or the amount of work to write the program in VIM and forget about all the gui fancy staff). Anyway FF is available and suprise, suprise, Studio 11 works almost out of the box. Here you go simple step by step guide to install this “little” precious.

1. Install Java SDK and JRE 5, for some reason SS11 doesn’t work with version 6, you can however still keep the version 6 as the default one on the system.
2. Install GNU C/C++ compiler under Ubuntu:

sudo apt-get install build-essential

3. Download Sun Studio 11 software for Linux
4. Run the installer:
change to root (su -)
move the downloaded .bz2 file to the directory where you want to install the software (in my case /opt directory)
run:
tar -xjvvf studio11-lin-x86.tar.bz2v
./installer –nodisplay
5. Answer a few simple questions about installation
6. Don’t worry if sdk 1.4 was not installed.
7. Change one of the awk scripts:
go to /installdirectory/sun/sunstudio11/prod/scripts/ver.awk
and change the line:

FS=“”| |(|)|,|t”;
to:
FS=“”| |(|)|,|t”;

8. Add the studio’s bin directory to your PATH:
Edit .bashrc and add the following line:

PATH=/opt/sun/sunstudio11/bin:$PATH; export PATH

9. Run the newly installed Studio 11 with:
sunstudio
Note:
If you have more than one JDK available and e.g version 6 is your default one, run sunstudio command with the following flag:
sunstudio=’sunstudio –jdkhome ‘path-to-your-jdk5or4′ in my case alias sunstudio=’sunstudio –jdkhome /usr/lib/jvm/java-1.5.0-sun-1.5.0.11′
If that is the case add the alias to your .bashrc file:
alias sunstudio=’sunstudio –jdkhome /usr/lib/jvm/java-1.5.0-sun-1.5.0.11′
and run the command sunstudio as normal.

Sun Studio 11 Splash Screen on Kubuntu 7.04 FF:


…and working IDE:

Good Luck :)