Search

Move the ubuntu 10.04 window button

tasklist_lock, tasklist_unlock are not exported by the kernel any more

If you are running a kernel module that was written before the kernel 2.6.17 was released, you might see code using the tasklist
rcu(tasklist_lock) , rcu(tasklist_unlock).

The codes that do use there symbols will not compile in the kernels after 2.6.17 cause, tasklist is not longer exported by the kernel . So  the modules do not have access to the symbols tasklist_lock and tasklist_unlock

png_info has no member by the name trans

If you get the error

png_info has no member called trans

while compiling directfb the following workaround might help

The name of the values "trans" and the "trans_values" has changed in the structure png_info defined in png.h

Open the file that is generating the error and change the values of

trans to trans_alpha
trans_values to trans_color

this should take care of the errors.

Your session lasted for less than 10 seconds

After doing lots of google and various trials , I was finally able to get the reason for the above problem.

Note: The same error can occur for various reasons, so my work around might or might not work for you.

The problem was with the permissions for the /tmp folder.

The permissions for the /tmp folder should be
rwxrwxrwxt
some one had changed this to
rwx------- 
So other than root no other user was able to start the Xserver session.
once I changed the permissions using :

sudo chmod a+rwxt /tmp

every thing is working fine.

Scripting - Looping

Looping in Scripts 

Let us say that we want to create 100 files, by the name file1,file2,file3...,file100. 
We could  execute the command "touch" with the file name a 100 times manually, which is a very time consuming and inefficient way of doing it. 
In scripting we have a work around for such repetitive job, loops. 

Loops are use when we want to execute a specific set of commands repeatedly a certain number of times or until some condition is not satisfied. 

Bash scripting provides us with the following kinds of loops 

for 
while
until

for : 

The syntax of the "for" loop is 

for  "var" in "list
do

{ block of commands to be executed } 
done 

e.g.: 

#!/bin/bash

for i in 1 2 3
do 
echo $i
done. 

Save the file as first.sh,give execute permission to the script and run it. 
The above example would give the output 
1
2
3

In the "for" loop we pass a list after the "in" keyword. The list can be list of any kind, each time one value of the list would be assigned to the variable and the loop will be executed. 
In the above example shown above, the first time the list was executed "1" was assigned to the variable "i", second time "2" was assigned and so on. 
The length of the list is not fixed, it can be as long as you want. 

e.g.:

for i in *
do 
echo $i
done 

Save the file as for2.sh, give execute permission and run it. 

In the above example we have used "*" in place of the list. 
What this does is repeatedly  assign the name of the files and folders in the present working directory to the variable "i". Thus when the loop executes, the script would act like the "ls" command and list out the contents of the present working directory. 

Bash also provides a special kind of "for" loop, which you would be familiar if you have done "c" programming. 

The syntax of this "for" loop is 

for(("initialise variable";"some conditional statement";"incrementing the variable"))
do
{Block of commands to be executed} 
done

e.g.: 

#!/bin/bash
for((i=0;i<10;i=i+1))
do
echo $i
done

Save the file as for3.sh, Give execute permission and run it.   

In the above format of the for loop, note that we need two "(".  
The first expression is initialising a variable to a value from which we want to start counting. In the above example we have initialised "i" to 0. 

The second expression is a conditional statement, the "for" loop  will keep executing as long as this statement is true. In the above example we have used the condition "i<10", which means keep executing the loop as long as the value of "i" is less than 10. 

The third expression is the value by which the variable should change each time a new iteration of the loop is started. In the above example we have used "i=i+1", which means we are increasing the value of "i" by one each time the for loop begins. 

So the above script will run the command "echo" 10 times, each time incrementing the value of "i" by 1. 

Note that the above format of the for loop is specific to bash, so if you want to run it with out giving the execute permission you will have to use "bash for3.sh" and not "sh for3.sh". 

While loop:

Syntax for while loop. 

while("condition statement")
do

{block of commands to be executed}
done 

The while loop is used when do not know the exact count of number of times we want to
execute the loop,but the loop execution is dependent on certain condition. 
As long as the condition being tested in the conditional statement is true, the loop will keep executing. 
The condition statement is implemented using the "test" command,as shown in the article  "Conditional Statements"

 eg: 

#!/bin/bash 
i=0
while[ $i -lt 5 ]
do 
echo $((i++)) 
done
echo "End of Loop"

Save the above script as while.sh, give execute permission and run it. 
The script should produce the output 
0
1
2
3
4
End of Loop

Note that the increment operator works only in the bash and not in simple bourne shell. 

The loop keeps executing till the expression in the conditional statement of the while loop is true. "i" starts with a value of "0" and each time it enters the loop the value gets incremented. Once the value of "i" becomes 5 the expression "i -lt 5" turns out to be false the script stops entering the loop and jumps to the statement after the loop, i.e. the statement after the "done" statement. 


Until loop: 

The until loop works like opposite of the while loop.
Syntax: 

until [ "conditional statement" ]
do 

{"block of commands'} 
done 

The until loop will keep running as long as the expression in the conditional statement is false, once the expression returns true the loop will exit. 
e.g.: 


#!/bin/bash
i=0
until [ $i -gt 5 ]
do 
echo $((i++)) 
done
echo "End of Loop"

Save the above script as until.sh, give it execute permissions and run it. 
It should produce the following output
0
1
2
3
4
5
End of Loop 

The "i" starts from the value "0", the expression in the until checks if the value of "i" is greater than false, which is false and hence it enters the loop. Each time the loop is executed the value of "i" is incremented by 1. As soon as the value of "i" becomes six, the expression "$i -gt 5" becomes true. Thus the until loop exits. 

Break: 

The break statement in useful when you want to stop a loop from continuing execution. 

 e.g.: 

#!/bin/bash 
i=0
while [ 1 ]
do
echo $((i++))
if [ $i -eq 5 ]
then
break
fi
done

Save the above script as break.sh,give it execute permission and run it. The script should produce the output 

0
1
2
3
4

In the script we have used a "1" in the while loop condition,which means it will always be true, and will keep executing the loop for ever. The break statement comes handy in such situations, when you want to stop a infinite loop is certain condition is met.  
In the script above the value of "i" is compared in the if statement with the "5", and when the value of i becomes 5, the script enters the if block where the break is executed. This causes the script to jump out of the loop it is currently executing, thus ending the script. 

Continue: 

"Continue" is useful when you want to skip to begin of the loop with out executing some of the statements. 
 eg: 

#!/bin/bash 
i=0
while [ $((i++)) -lt 5 ]
do
if [ $i -eq 2 ]
then
continue
fi
echo $i
done

Save the above script as continue.sh, give it execute permission and run it. You should see the output 
1
3
4
5

The script keeps comparing the value of "i" with 2, and when the value becomes "2" it enters the if block where the "continue" gets executed which causes the script to skip to the beginning whit out executing the remaining statements in the script. That is why the value "2" does not get printed in the output while rest of them do get printed.  


Try it out: 
1. Write a script that will list out only the files in your current folder. (Hint use the "test" and the "for loop")
2. Write a script that will create a back up of every file in your directory in a subdirectory by the name "backup". 
3. Write a script that will list only the first 5 latest modified files in your current directory. 
(Hint: Use "for i in `ls -t`" along with "break") 
4. Write a script that will prompt the user for a file name, and search for the same in the current directory. If the file exists echo "File present" else echo  "File not found". 
5. Write a script that will give execute permission to all the files that end with the extension .sh. (Hint: use "for i in *.sh" )

Enabling Atheros Ethernet controller on ubuntu (AR8151)

If you have installed ubuntu in your system and it has a Atheros network controller ,your network card will not be detected.

If you don't know what enternet controller is present run the command

lshw -class network 

It should list out all the network controllers present, if you see Atheros/Attansic in the list then do the following to enable your card. 


The ubuntu distros by default don't have the drivers for the Atheros/Attansic drivers and hence need to be installed. 
Download the package from
http://partner.atheros.com/Download.aspx?id=162
(this works for AR8151, might work for all 81 series too) .
NOTE: The link is not working any more after take over of atheros by qualcomm. Will update once I get the correct link.
Please refer to the comment by kodb for update
Thanks for the update NO the driver can be downloaded from

Once you have downloaded the .gz  pacakage, put it into a empty folder and run the following commands Your network should be recognized now, have fun :-)

Conditional Statements

Using conditional statements in scripting.

Often in scripts we might want to certain things only if some other condition is satisfied
For e.g.:
Display the contents of a file if the file exists.

For such conditions we use the "if" statement in scripting.

Syntax


if("condition statement") then


{block of commands to be executed } 


fi


The "if" statement starts by checking some condition mentioned in the "condition statement" . If this condition is true, then it executes the block of statements given next until the "fi". Which marks the end of the if block.
After the "fi" the script continues as usual.

If the condition turns out to be false, then the script directly jumps to the statement after "fi", not executing any of the statements between "if" and "fi".

The conditions are checked using the "test" command. The test command has various options available with it, which are listed in the man page of test.

for e.g.:
To check the existence of a file  we use  " test -e "file name"  "
So with the "if" statement if would be

#!/bin/bash 
if( test -e temp) then
echo "It exists " 
fi

Save the file as if.sh, give execute permission and run it.

If your current working directory has a file by the name "temp", then the output will be
"It exists"  other wise there will be no output.

If you want to compare two numbers

#!/bin/bash


echo "Enter the first number" 
read i;
echo "Enter another number" 
read j;
if( test $i -gt $j) then
   echo "$i is greater"
fi
if( test $j -ge $i) then
        echo "$j is greater or equal"
fi

Save the script as if2.sh, give execute permission and run it.

The script will prompt you to enter 2 numbers, The numbers you enter are compared
with each other using the test command. Note that to compare numbers we use the letter

-gt greater than
-lt lesser than
-eq equal to
-ge greater than or equal to
-le lesser than or equal to
-ne not equal to.

Note that these letters are used only with numbers and not with strings or characters. String comparison is shown below.

The stings are compared using

STRING1 = STRING2
STRING1 != STRING2
-n STRING To check if the string length is non Zero
-z String to check if the string length is Zero.

Eg:

#!/bin/bash 
password="pass" 
read  auth
if (test $auth = $pass)then 
echo "Log in successful" 
fi

Save the above script as string_chk.sh, give it execute permission and run it.

The script has a variable, password, that has the value "pass". The script prompts the user to enter a string. The string entered by the user is checked with the previously stored string, if they match then script enters the "if" block and prints "Log in successful".

In the example above we printed "Log in successful" when the user enters the correct string, but what about the condition when the user does not enter the correct sting.
For such cases we need to make use of the "else" statement.

Eg:

#!/bin/bash 
password="pass" 
read  auth
if (test $auth = $pass)then 
echo "Log in successful" 


else 
echo "Wrong password" 


fi

Save the above script as else.sh, give it execute permission and run it.

The script should print "Log in successful" if you enter the correct string, and print
"Wrong password" if you enter the wrong string.
The "else" block is executed only when the "if" condition fails or is false.

Now one more thing that we might want to do is check multiple conditions.

for eg:

#!/bin/bash 
echo "enter your age" 
read age


if(test $age -gt 18) then
echo "you are eligible for license" 


elif(test $age -gt 16)then 
echo "you can get a temporary license" 


else 
echo "you will have to wait till you become 18" 


fi

Save the script as elseif.sh, give it execute permission and run it.

The script prompts the user to enter their age, the age is compared with the number "18". If it is greater than 18, then it prints out the message "You are eligible for license"
. If this comparison turns out false, that is the age entered is less than 18, then it is the age is again compared with "16". To this second comparison, we use "elif" .
"elif" is executed only if the condition in the previous "if" condition turns out to be false. We can have as many "elif" one after the other as we want, each "elif" would be executed only if all the "if" and "elif" above it turn out to be false.
 If the condition in the "elif" also turns to be false we have included as final else, which is executed when all the "if" and "elif" become false.

Bash also has a special feature, instead of using the test condition we can use "[".
They both work in the same way.
For eg:

#!/bin/bash 
echo "enter your age" 
read age


if [ $age -gt 18] 
then
echo "you are eligible for license" 


elif [ $age -gt 16 ]
then 
echo "you can get a temporary license" 


else 
echo "you will have to wait till you become 18" 


fi

Save the above script as "bracket.sh", give it execute permission and run it.

The script should run exactly same as the previous example elseif.sh.
But in this script, if you notice, we have not used the "test" statement but instead we have used the "[" which is same are "test" in bash. The only difference between the usage of "test" and "[" are
The "[" has the followed by a empty space, as it is also a command. But in case of test we need not have a space after the "(".
The "then" statement comes in the next line.
The space before the closing "]" is also required.

Bash also supports nested ifs, i.e we can use a if condition when inside another if block.
For eg:

#!/bin/bash 
echo "enter the car name"
read car 
echo "Enter the year of manufacture"
read year 


if [ $car = "mercedes" ]
then 
  if [ $year -gt 2000 ]
  then
echo "I will buy" 
   else 
echo "its too old"
   fi 
else 
echo "Not my type of car"
fi 

Try it out:

1. Write a script that will ask the user year of birth, then calculate his age and
   and then print out if he is an adult or a minor.
2. Write a script that will ask the user to enter their marks and output their grade     based on the following scale
90-100 Grade A
70-90  Grade B
60-70  Grade C
50-60  Grade D
< 50   Grade E

.nrg to .iso conversion

If you are stuck with a nero image of a CD, and wante to convert it to a .iso image so that you can create a bootable CD here is a simple solution.

Download and install a tool called  nrg2iso

sudo apt-get install nrg2iso 

Open a terminal  and type

nrg2iso "Source_filneame.nrg"  "Destination_filename.iso" 

Simple as that, now you have an .iso image ready, have fun.

Modifying the run level in Ubuntu 10.04

If you are running ubuntu 10.04 and are looking for the file /etc/inittab, you most probably will not find it. That is because ubuntu has changed a little the files that are read during the system boot.
The runlevel is now set by the file /etc/init/rc-sysinit.conf.
The default Runlevel is set to "2" which is the normal graphical mode.
If you have used any previous versions of linux you would be used to Graphical level being the run level 5, but that is again changed in ubuntu.

If you want change this run level you can set it as follows


1. Open a terminal
2. Run the command "sudo gedit /etc/init/rc-sysinit.conf"

3. In the file that opens search for the line
 env DEFAULT_RUNLEVEL=
4. After "=" enter the new runlevel number you want  and save the file.
5. Let  say we want to boot into text mode every time, so put "3" after the "=" and save the file
6. Now to start in text mode we need to stop gdm from loading , open the file gdm.conf using
"sudo gedit /etc/init/gdm.conf
7. You will see the following set of lines


start on (filesystem
          and started dbus
          and (drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1
               or stopped udevtrigger))
stop on runlevel [016]

Change it to
start on (filesystem
          and started dbus
          and (drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1
               or stopped udevtrigger))
     and runlevel[!3] 
stop on runlevel [016]


and runlevel[!3]   was the new line added.

Save the edited file and restart, it should boot in text mode.

Another way of changing to text mode is to pass the argument "text" to the kernel while booting.
we can do this as follows

1. While the sytem boots hold the "shift" key so that the gurb menu gets displayed
2. Move to the line that has the kernel you boot, some thing like

Ubuntu, with Linux 2.6.32-28-generic

3. Press "e"
4. Move to the line that starts with "linux"
5. Press e again to edit and at the end of this line add the word "text" and press enter.
6. Press cntrl+x to boot the system in text mode.

You can also add a permanent option in your grub menu for the text mode which can be done as follows.
1. Open the file /boot/grub/grub.cfg  using "sudo gedit /boot/grub/grug.cfg"
2. Go to the section that starts with "BEGIN /etc/grub.d/10_linux"
3. Copy the menuentry of the kernel you want to boot in text mode.
4. Open the file /etc/grub.d/40_custom using "sudo gedit /etc/grub/40_custom"
5. Paste the entry copied from grub.cfg at the end of this file.
6. In menuentry add the string "text" at the end of the line that starts with "linux" and save the file
7. Run the command "sudo update-grub2"
8. Now restart the system and hold shift to see the grub menu.
9. You should see a new entry at the end, which if selected should boot into the text mode.


Restore the Default Panels in ubuntu

If you have deleted the panels of your ubuntu, top or bottom one and can not figure out how to restore it here are three simple commands that will give your default panel back.
Note that the panels will be restored to the way they look when you have a fresh install, any shortcuts etc that you might have added to them will not be available and you will have redo them.

1. Open a Terminal Type the following commands
2. gconftool --recursive-unset /apps/panel 
3. rm -rf ~/.gconf/apps/panel
4. pkill gnome-panel





After running the above commands you should see both your top and bottom panels 
being restored to their default states.