Monday, 19 November 2012

Checking the existence of a database using shell script

#!/bin/bash

#############################################
# script to check whether database exists or not                                      
#                                                                                                                    
#                                                                                                                    
#                                                                                                                    
# Made By : Damanpreet Singh (DEMON)                                                   
# http://damanpreet.co.cc/                                                                            
#                                                                                                                    
#                                                                                                                 
# created : 13-11-2012                                                                                            #   VER=1.1                                                                                              
#                                                                                                                
#############################################

echo "enter mysql username"
read u
echo "enter mysql password"
read p
echo "enter database name to check"
read db_name
RESULT=`mysql --user="$u" --password="$p" --skip-column-names -e "SHOW DATABASES LIKE '$db_name'"`
if [ $RESULT ]; then
    echo "Database exist"
else
    echo "Database does not exist"
fi

Thursday, 4 October 2012

arrays in shell script

I needed to make changes in a file that is downloaded to the system,
the changes include inserting the database name, database user_name,
etc. Firstly I tried so many methods but they were insufficient and
did not solve the purpose correctly, so I tried changes to it and was
able to do so. I could make changes to the settings.py file( the file
i wanted to make changes to) using "sed" command(sed=stream editor).
There was one big problem, I was using the same command multiple
times, so I used the for loop and put the different elements in
arrays.
Harman's mail on using arrays in shell script was very helpful, I
faced very less problem thanks to it. Secondly, I restricted the use
of sed to particular lines(rows in file) specifying the line in a
array .
Now what I have just made(just the main part):


###########################################################
array1=("db_name" "db_user" "db_password" "user_name" "email_add")
array2=("15" "16" "17" "86" "110")

len=${#array[*]}

file=Automation/settings.py

i=0
while [ $i -lt $len ]; do
        read -p "${array[$i]}" ${array1[$i]}
        #echo ${!array1[$i]}
        sed -i "${array2[$i]} s/${array1[$i]}/${!array1[$i]}
/" $file
        let i++
done
###########################################################

This code works fine, but I need to improve it.
 
 

Sunday, 30 September 2012

jason statham - the transporter





 I only have two rules. Rule 1, no names. Rule 2, there is no such thing as rule 2. ;-)-----transporter2

Thursday, 9 August 2012

Adding Django-catalog

Django-catalog
This application was created to organize the objects in a tree structure.

Installation
A. Download

At present, a stable release Django-catalog there, but you can download the development version from the repository on github

pip install django-catalog


Two. Connect the application

To connect the installed Django-catalog, add in your project settings.py configuration file the following contents

INSTALLED_APPS = (
    'Catalog',
    'Catalog.contrib.defaults',

)
Three. Connect URLs applications

Add the URL of the application in the Django-catalog of your project urls.py

To use the scheme to access items on the tree slug

urlpatterns  = patterns ('',
    (r '^ catalog /', include ('catalog.urls.by_slug')),
)

To use the scheme to access elements of a tree on their id

urlpatterns  = patterns ('',
    (r '^ catalog /', include ('catalog.urls.by_id')),
)

4. Creating models

In order to use the directory to create for him a model. Previously, we hooked INSTALLED_APPS application directory implements the basic models and methods of work with them. At this stage, to ensure the health directory, we have enough. Start the synchronization of the database to create a catalog of standard models

python manage.py syncdb

Five. The administrative interface

To fill the catalog of categories and products go to the Django administration interface and select the Manage catalog.

6. The use of templates

Django-catalog is supplied with ready-made templates for the work, which should be enough to start using the directory.

Friday, 3 August 2012

Matrix on terminal

First of all, install cmatrix using the following command:

$ sudo apt-get install cmatrix

After cmatrix is installed, run the followinf command with different options such as, -a, -b, -B, etc

$ cmatrix -b

and what you get is the output. :-)

Terminal music player

For the past two months i have been using terminal(mplayer) to play my
songs, I found it quite interesting to use terminal to play music than
using some other applications. I learnt how to use mplayer and run
songs on it, everytime I had to select a song, then play it and run
the command

mplayer abc.mp3

Then came the issue of playing multiple songs, used

mplayer *.mp3

Then I wanted the songs to play in a random pattern(shuffle). For that
I created a playlist in the directory containing the .mp3 files and
ran command

 find -type f -iname \*.mp3 > demon.txt

and hence a playlist named demon.txt is created, I would run it using
the command

mplayer -shuffle -playlist demon.txt

this would play songs in shuffle pattern. I created a script to play
songs in shuffle. But there was a problem that the script would run
only if the Drive containing .mp3 files and the playlist was mounted,
and if the drive was unmounted it would show error. I then learnt to
Mount drive using terminal commands and making small changes, and made
a script that would play when the drive was unmounted. One can learn
how to mount a drive from terminal from
https://help.ubuntu.com/community/Mount/USB

Now i have finally made a script, that checks whether the .mp3
containing drive is mounted or not, if the drive is mounted it simply
plays song from the playlist demon.txt.
and if the drive is not mounted, the script would fetch another script
in my folders that would unmount the drive and then run the playlist
demon.txt.

Here is the script i use, kept in my home folder
http://202.164.53.122/~daman/scripts/hi.sh

And the other script I use to Mount
http://202.164.53.122/~daman/scripts/demon.sh


I am really happy, removed banshee and rhythm box from my system :D.

Wednesday, 13 June 2012

ways to see text using terminal commands

Following are some ways to display data in different applications using following commands:

To see text in Gedit
demon@demon-pc:~/ gedit text.txt

To see text in vim
demon@demon-pc:~/ vim text.txt

To see text in office(Libre Office)
demon@demon-pc:~/ soffice text.txt

We can use the same for GEANY.