About My Blog



Whenever I get stuck doing something - the time comes to venture in the world of internet to find solution. In most cases I do find the solution, solve my problem and go on with my life. Then one day I am faced with the same problem. But now - I can't remember how the hell I solved it the first time. So the cycle begins again. Then I thought, what if I can remember all the those things? So here it is, my Auxiliary Memory. I decided to save all the problems and their solution in this blog so that I can get back to them when I need them. And the plus point is - so can everybody else.

Friday, October 31, 2014

Batch File Renaming with Windows PowerShell

I have been in situations where I needed to batch rename a lot of file. There are a lot of tool you can find on internet that can do this. But why go through all those software when you have one option available in windows ready for you to use.

Say Hello to PowerShell. To open it just type "powershell" in command prompt or in start menu.

Here are a few things you can easily do with powershell

Change File Extension

Have some .log whom you want to change to .txt? Just run the following command -

dir *.jpeg | rename-item -newname {  $_.name  -replace ".log",".txt"  }

dir command gets the list of files in the current directory. The | (pipe) character passes this list to rename-item command which takes each of the file and replaces it's extension

Appending File Extension

You can append file extension to multiple files which don't have file extension in their name

dir | rename-item -newname  { $_.Name +".jpg" }

Rename File With Increasing Number

This one's a bit complicated than the other two. It uses a variable to rename the files.
dir *.jpg | ForEach-Object  -begin { $count=1 }  -process { rename-item $_ -NewName "image$count.jpg"; $count++ }

Accessing Physical Hard Disk Partition From Virtualbox Guest

  1. Run virtualbox with admin privilege.
  2. First we need to find the partition number. For that we need to run the following command.
    "c:\Program Files\Oracle\VirtualBox\VBoxManage.exe" internal commands listpartitions -rawdisk "\\.\PhysicalDrive0"
  3. This will show the list of partitions (We need to run command prompt as administrator also for this to work). For my case
    Number  Type   StartCHS       EndCHS      Size (MiB)  Start (Sect)
    1       0x07  0   /32 /33  44  /190/18           350         2048
    2       0x07  44  /190/19  1023/254/63        204450       718848
    3       0x07  1023/254/63  1023/254/63         66560    419432448
    4       0x07  1023/254/63  1023/254/63        205578    555747328
  4. Now we need to create a .vmdk file that will point to the partition we need. I am going to attach mine with partition 4.
    "c:\Program Files\Oracle\VirtualBox\VBoxManage.exe" internal commands createrawvmdk -filename "E:\VirtualboxVDIs\rawedrive.vmdk" -rawdisk "\\.\PhysicalDrive0"  partitions 4
    RAW host disk access VMDK file E:\VirtualboxVDIs\rawedrive.vmdk created successfully.
  5. Bingo :). Now we need to attach the .vmdk file to a guest OS. Need to run VirtualBox Manager with admin privilege also.
  6. Select the guest OS from virtualbox manager and goto its settings
  7. Select storage tab and add the vmdk file to the SATA controller.
  8. Now startup your guest OS and you will find your hard drive their

One problem with this is that you cannot mount the hard drive in both guest and host at the same time. If your host is windows just remove the drive letter associated with the partition from device manager to unmount it.

Details can be found in this link

Thursday, October 30, 2014

You don't have permission error in Apache in CentOS

The Problem

I have installed apache 2.2 in centos 6. Everything worked fine when the apache folder was at its default location /var/www/html. Then I configured a Virtual host inside my users home folder. After that apache started showing Forbidden You don't have permission error when I tried to go to localhost or 127.0.0.1 from browser. this is the code i used in httpd.conf
<VirtualHost *:80>
        DocumentRoot "/home/anjan/workspace/mfs"
        ServerName anjan-centOS
        <Directory "/home/anjan/workspace/mfs">
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order Deny,Allow
                Allow from all
        </Directory>
</VirtualHost>

I also disabled SElinux as was mentioned in some articles but in vain. If anyone could help me out it would be much appreciated.

The Solution

I solved the problem. After meddling with the permission of the system I found out that the user "anjan" who is owner of /home/anjan had read/write/execute permission on /home/anjan but the group "anjan", created when user "anjan" was created didn't have any permission at all.
ls -l /home/
showed
drwx------. 28 anjan anjan 4096 Jan 21 13:19 anjan
so I changed the permission with this command
chmod -R 770 /home/anjan
ls -l /home/
drwxrwx---. 28 anjan anjan 4096 Jan 21 13:19 anjan
i found out under which user my apache is running from this thread. It was running under user "apache" so I added user "apache" to group "anjan" with this command.
usermod -G anjan,apache apache
after that voila. No more Forbidden error.