Tuesday, June 26, 2012

SHell saved the day!

I was having trouble letting my students start the processing IDE in our somewhat "super lag" computer lab. All options failed. Then I came to realization that I have to do the dirty job myself. This would include the following task applied repeatedly to student's individual directory:
  1. Accessing the student direcotry
  2. Access the Directory where I put the "zipped" IDE
  3. Extract the File
  4. And proceed to the next student directory.
This could go on forever should I choose to manually do the tasks one folder at a time. Then "light bulb", why not automate those tasks using a shell script. So after googling for some shell commands and syntax I finally arrived to the code below:
#!/bin/sh
#This is a simple shell script program to traverse all the directories containing
#the file  processing-1.5.1-linux.tgz stored inside csc 100 directory
#Programmed by: Orven E. Llantos

for file in *
do
 if test -d $file
 then cd $file;cd csc\ 100/; tar zxvf processing-1.5.1-linux.tgz; cd ../..;
 fi
done
The for-loop will access all the files in the current directory, then the if statement tests whether the current item is a directory, if it is then do the associated tasks otherwise do nothing. And done. Running this script saved me, to generalize the code above for it to do whatever you wanted to do repeatedly given a set of directories we can re-write it as:
#!/bin/sh
#This is a simple shell script program to traverse all the directories containing
#the file  processing-1.5.1-linux.tgz stored inside csc 100 directory
#Programmed by: Orven E. Llantos

for file in *
do
 if test -d $file
 then ;
 fi
done
Hope this could help you too. Fin.

Monday, June 18, 2012

what to do when you see this? --> /boot is using 87.7% of 227MB

When I remotely logged in to a server I maintained, I was alarmed by this message:

    /boot is using 87.7% of 227MB

It's kind of "something" that you'll get yourself to worry because it may have some adverse effect into your server. So then, I googled and found out some potential solutions, the best one I found here. From the previous threads I read, this problem usually occurs when after you updated your server's kernel you still keep the old versions. And if you repeatedly do this, you will eventually run out of space in /boot.

The key idea is, after you install a new kernel you have to remove the old one. But you only do this after you have tested the new kernel  and everything works fine with it.

So, here are the things you need to do in removing the old kernels using a command line. (Synaptic has alternative of doing this via GUI)

Step 1. Paste this code into your .bashrc file.
rmkernel () {
        local cur_kernel=$(uname -r|sed 's/-*[a-z]//g'|sed 's/-386//g')
        local kernel_pkg="linux-(image|headers|ubuntu-modules|restricted-modules)"
        local meta_pkg="${kernel_pkg}-(generic|i386|server|common|rt|xen|ec2)"
        sudo aptitude purge $(dpkg -l | egrep $kernel_pkg | egrep -v "${cur_kernel}|${meta_pkg}" | awk '{print $2}')
}

Step 2. Run source .bashrc
Step 3. Then rmkernel 

After Step 3, you will be prompted to enter the admin password and it will list the kernels installed in your system, mine looks like this: 
The following packages will be REMOVED:  
  linux-headers-3.0.0-14{pu} linux-headers-3.0.0-14-server{pu} linux-headers-3.0.0-15{pu} linux-headers-3.0.0-15-server{pu} 
  linux-headers-3.0.0-16{pu} linux-headers-3.0.0-16-server{pu} linux-headers-3.0.0-17{pu} linux-headers-3.0.0-17-server{pu} 
  linux-headers-3.0.0-19{pu} linux-headers-3.0.0-19-server{pu} linux-headers-3.2.0-24{pu} linux-headers-3.2.0-24-generic{pu} 
  linux-image-2.6.38-11-server{p} linux-image-2.6.38-12-server{p} linux-image-2.6.38-13-server{p} linux-image-2.6.38-8-server{p} 
  linux-image-3.0.0-14-server{p} linux-image-3.0.0-15-server{p} linux-image-3.0.0-16-server{p} linux-image-3.0.0-17-server{p} 
  linux-image-3.0.0-19-server{p} linux-image-3.2.0-24-generic{p} 
0 packages upgraded, 0 newly installed, 22 to remove and 43 not upgraded.
Need to get 0 B of archives. After unpacking 1,617 MB will be freed.
Do you want to continue? [Y/n/?] y

After you answered "y"es, more messages to appear on the screen and after that, you will only be left with one kernel in you /boot. To verify, you can issue this command:  ls -alt /boot/initrd.img* . You should only see one listing, and that is your current kernel.

Fin.