Tuesday, April 23, 2013

Ubuntu Server 12.10 Quantal Crontab scheduling

Today, I spent quite some time to figure out why my crontab did not work as I expected. I supposedly thought that I had set to it to run every 2 minutes but it did not. After giving up for sometimes and came back to realise it works but instead of running every 2 minutes, it run at every hour's 2 minute. Further reading let me found  the correct way. To add task we run crontab by typing crontab -e 
 The format for crontab are as followed:
           mins hour day-of-month month day-of-week   command

          Example to run the php script every 5 minutes, we will do the following:

           mins hour day-of-month month day-of-week   command
           */5     *             *                  *             *              /usr/bin/php  /home/username/script.php

          If you would like it to run for example every 15 minutes, you will put */15 instead.

Wednesday, April 17, 2013

Fact of the day - M&M were orginally created to allow easy transport of chocolate to the military


Forrest Mars, Sr., son of the founder of the Mars Company Frank C. Mars, invented the idea for the candy in the 1930s during the Spanish Civil War when he saw soldiers eating chocolate pellets with a hard shell of tempered chocolate surrounding the inside, preventing the candies from melting.

The practicality of the candies during World War II caused an increase in production and its factory moved to bigger quarters at 200 North 12th Street in Newark, New Jersey where they remained until 1958 when it moved to a bigger factory at Hackettstown, New Jersey. During the war, the candies were exclusively sold to the military.


Source: Wikipedia


Tuesday, April 16, 2013

How to control windows 7 & 8 snap feature with multiple monitor

Have you tried to snap your opened document to the left/right of your screen but it opened up in full? You might face this problem if you have multiple monitor with extended display. 

What you can do is press "Windows Key" + "Left arrow/Right arrow" to snap the selected window to left or right. By continuing pressing the "Left arrow/Right arrow" while holding down  "Windows Key", you can snap the selected window to your other monitor.

Sunday, April 14, 2013

PHP session timeout

We can add this simple code to create a session time out when no activity for a certain duration. 

<?php
$duration=900; //set how long before timeout in seconds
//If it is longer than duration set, time out occurerd and session will be destroyed
if(time() - $_SESSION['LAST_ACTIVITY'] > $duration)
{
session_unset();
session_destroy();
exit;
}
else //If last activity is within 900s, refresh the last activity time
{
$_SESSION['LAST_ACTIVITY'] = time();
}
?>

Friday, April 12, 2013

Create shutdown and restart shortcut icon for Windows 8 Metro ui

Step 1. Open "Computer" and browse to "C:\Users\Name\AppData\Roaming\Microsoft\Windows\Start Menu\Programs".

Step 2. Create a shortcut by "right click->New->shortcut".

Step 3. A "Create Shortcut" dialog will open and enter the following to the field and click next:
C:\Windows\System32\shutdown.exe /p


Step 4. Give the shortcut a name and click finish to create the shortcut.


Step 5. Repeat Step 2-4 again but enter the following for Step 3 to create a restart shortcut instead:
C:\Windows\System32\shutdown.exe /r /t 0

The shortcut for shutdown and restart is now completed. To give it a nice icon, go to google and search for .ico file. To set icon for the shortcut, right click on it and go to "property". Click on "Change Icon" and browse to the location of the .ico file you have downloaded and click "ok". You are all set to use the newly created shortcut.



The shortcut in metro ui

Thursday, April 11, 2013

How to auto start vmware guest OS when Windows host computer restart

Step 1. Create a new text file and save it as "startVM.bat"

Step 2. Ensure that the path of vmware is added in envrionment variable and enter the following into the "startVM.bat" and save:
vmrun -T ws start "Your_VM_Image.vmx"
Step 3. Open up "Task Scheduler" and select "Create Basic Task" under "Actions" tab.


Step 3.1 Give the task a name and click next.


Step 3.2 Choose "When the computer starts" when asked when you want the task to start.


Step 3.3 Choose "Start a program" when asked what action do you want the task to perform.


Step 3.4 Under "Program/script", browse to the location where you saved the "startVM.bat"


Step 3.5 Check "Open the properties dialog for this task when I click Finish" and click "Finish".



The "startVM.bat" is now scheduled to run when computer start. Now we will tweak the task to start one minute after the computer start so to allow the system to start up all the services before running the vmware. 

Step 4. Go to "Triggers" tab and double click on the trigger in the list.


Step 5. Check "Delay task for:" under "Advanced settings" and choose "1 minute". Press "ok" and you have successfully configure your vmware OS to auto start when your host OS restart.




Wednesday, April 10, 2013

How to shrink Linux .vmdk file on Windows host

Ever face the problem of your Linux image file keep growing bigger in size while the actual usage is smaller? I encountered this when my apache server created a massive 15GB log file and after deleting the log file, my image file is still 15GB+.

 Follow the steps to reduce the image file.

Step 1. Fill the unused space with zero with the following command:
sudo cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill
Wait for it to complete as it will take some times to complete depending on the assigned storage size.

Step 2. Power down the Linux guest OS when Step 1 complete.

Step 2.   If you have not set a path for your vmware, locate the location of where you installed your vmware. For mine, it is located at "C:\Program Files (x86)\VMware\VMware Workstation".

Step 3. Open command prompt and browse to the directory of the .vmdk file you want to reduce and enter the following command to begin shrinking:

"C:\Program Files (x86)\VMware\VMware Workstation" -k "Your_Image_File.vmdk"