Tuesday, July 8, 2014

How to install ubuntu using bootable pendrive

If you are on windows and want to create bootable pendrive for ubuntu, then follow the following steps:

1. First you have to get the iso file of the ubuntu. You can get that here: http://cdimage.ubuntu.com/daily-live/current/ or you can download from your local server.

2.Download the Universal USB installer from here http://www.pendrivelinux.com/universal-usb-installer-easy-as-1-2-3/ and make your USB stick bootable. The instruction is give in the same site.

3.Change the boot order of your PC. Give the first priority to the USB.

Sunday, January 26, 2014

django: permission denied: '/home/www-data'

Recently, I got a  error ("permission denied: '/home/www-data' ") in django. Couldn't figure out the problem for a while...... but finally i got the solution.

1. What i was trying to do......
     I have built a django application(that runs on apache server in production environment) that records all the user data, customer data and all the transactions. I was trying to add the feature that back-up the database to the location , "/home/binod/database-backup/xxxx-xx-xx", where binod is the username of the system and database-backup and xxxx-xx-xx (which is the current date) are the sub-folders inside "/home/binod/", are created dynamically by the system.


2. What happened............
    Everything was fine in development environment. I was happy :) .
The code was:

@login_required
@user_passes_test(lambda u:u.is_superuser)
def backUpDatabase(request):
    args = {}
    
    now     = datetime.datetime.now()
    now_time = str(now.hour)+"-"+str(now.minute)+"-"+str(now.second)

    today = now.date()
    today = dateConverter.english_to_nepali(datetime.date.today())
    today = str(today.year)+"-"+str(today.month)+"-"+str(today.day)
    
    import getpass
    user = str(getpass.getuser())             #this gets the current username i.e binod for my system [what i expected :( ]
    
    backup_base_dir ="/home/"+user+"/database-backup/"        
    backup_sub_dir  =backup_base_dir+today+"/"
    backup_filename =backup_sub_dir+today+"-"+now_time+".sql" 

    import os
    
    if not os.path.exists(backup_base_dir):
        os.makedirs(backup_base_dir)

    if not os.path.exists(backup_sub_dir):
        os.makedirs(backup_sub_dir)
    
    from projectUCN import settings
    password =settings.DATABASES['default']['PASSWORD']
    return_value = os.system("mysqldump -u root -p"+password+" projectUCN > "+backup_filename)

    if return_value == 0:
        from django.contrib import messages
        messages.success(request, "database has been successfully saved to  \""+backup_filename+"\"")

    return HttpResponseRedirect('/admin/databaseOperation/')

I got exactly same output in development environment what i had expected but while running in production environment, I got the error permission denied: '/home/www-data'















3.What I did.........

The problem was with the line

    import getpass
    user = str(getpass.getuser())             #this gets the current username i.e binod for my system [what i expected :( ]
                                                                   #But this gets the username 'www-data '    :D
    
    backup_base_dir ="/home/"+user+"/database-backup/"        
    backup_sub_dir  =backup_base_dir+today+"/"
    backup_filename =backup_sub_dir+today+"-"+now_time+".sql" 

so, 
 backup_base_dir  becomes  "/home/www-data/database-backup/"    and so on.......

 So, the solution is replace the user by the current username . i.e
 backup_base_dir  becomes  "/home/username/database-backup/"

Wednesday, February 20, 2013

Navigation


Know your current working directory

To know about the current directory you are working with, just type pwd (print working directory) and hit enter key. The output is like in the snapshot below.
ImageThis shows that my current working directory is "/home/binod".
So, this shows your current directory. What if , if you want to change your directory? Here goes the solution.

Changing the directory

To change the directory using terminal, type cd <path name>.  The pathname can be Absolute or relative to current working directory. As for example if I have to change my directory to the Desktop from my current working directory, what i have to do is:
Imageso this changed my current working directory to the Desktop.
[Note: if you simply type "cd" and hit enter key, the working directory will changed to "home" directory. (also try "cd  ~" and "cd  /")]
for full details see man page for cd ("type "man cd")


List the directory contents

The command lists the contents of the directory specified by the user. By default, It lists the contents of the current working directory.
To list the directory contents type "ls" in the terminal.Image
for full details see man page for ls ("type "man ls")

Step in to command line


Let's get started.

Note:
All the commands I use here is for the Ubuntu, these commands may or may not work on the other linux distribution.

At first open your terminal emulator, you can start it either by Applications->Accessories->Terminal or by using the shortcut Ctrl+Alt+t. 
When it starts, the text there might be like this:
Image
This is in the format username@machinename:currentdirectory$. 

Now let's start typing some command:
If you type date, it displays the current date. And the output looks like:
Image

Similarly you can use,
cal - to display the calendar
Image

Now, check these commands yourself.
free- to display the free space in the memory(RAM)
df- amount of free space on your disk drives
and many more.

and finally to the end the terminal session you have to type exit and hit enter key.

If you have any problem regarding any command, just type man <command> . It displays the manual page for the command specified.

As for example, to view the manual page of ls(lists the directory contents), just type man ls in the terminal.

Sunday, January 20, 2013

LINUX TERMINAL TUTS


Why Use The Command Line?

Most computer users today are only familiar with the graphical user interface (GUI) and
have been taught by vendors and pundits that the command line interface (CLI) is a
terrifying thing of the past. This is unfortunate, because a good command line interface is
a marvelously expressive way of communicating with a computer in much the same way
the written word is for human beings. It's been said that “graphical user interfaces make
easy tasks easy, while command line interfaces make difficult tasks possible” and this is
still very true today.



Unlike windows , command line in linux has much more power.


screenshot for the terminal in Ubuntu 12.10



Shell, Terminal, Konsole ???????????????????


SHELL

In Linux when we say command line it is actually referring to the shell. The shell is a program (more specifically "command line interpreter") that takes the input from the keyboard and passes to the operating system to perform the specified task. BASH (Bourne Again SHell) ,a GNU project ,is a shell program that all Linux distributions provide. The emulator might vary from one distribution from others. bash is an enhanced replacement for sh, the original Unix shell program written by Steve Bourne.

for further study on shell


TERMINAL
As I've said that shell is a Command Line Interpreter, then how to interact with the shell????? any idea??
The solution for this is the terminal. Actually this is a GUI program which can be controlled by use of pointers. The different terminal emulators available for the Linux are:

GNOME-Terminal for GNOME
Konsole for KDE
and so on...

whatever the names are, they all do the same things.