8 Ekim 2012 Pazartesi

Batch - Run A Command Repeatedly In Each N Seconds

Sometimes you need to execute some command repeatedly in each n second(s). May be, you are listening a change on a file, a database or something another. If you don't want to fire same command again and again manually, you can use my listen.bat script. For example, you can check count of needles in the :
listen 3 grep "needle" "haystack.txt" -c

Script is below (gist here):
@echo off

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: This script executes given command repeatedly.
:: Waits specified amount of time between two executions.
:: First parameter MUST be sleep time.
:: Rest of the parameters will be executed as a command.
:: This script relies on sleep command from GnuWin32 package.
:: 
:: usage: (1 minute = 60 seconds intervals. More info: sleep --help)
::    listen 60  grep -w needle "haystack.txt"
::    listen 60s grep -w needle "haystack.txt"
::    listen  1m grep -w needle "haystack.txt"
::
:: @author: mmdemirbas@gmail.com
::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: First argument is expected to be sleep time
set SLEEP_TIME=%1

:: Other arguments will be a command with or without some parameter(s)
set command=
:init
shift
if [%1]==[] goto exec
set command=%command% %1
goto init

:exec
 call %command%
 sleep %SLEEP_TIME%
goto exec

How to Boot Last Used Boot Entry in Ubuntu & Windows Dual-boot?

Every time I installed Linux in my machine, I want to set Windows as default boot entry in the GRUB. So, I have not to wait GRUB screen to boot Windows and I have to wait only when I want to boot Ubuntu.

While searching how to do it, yesterday I came up to an askubuntu.com answer explaining a very useful tip about the subject. Do you want to boot Ubuntu as default at every boot time until selecting Windows manually; and then boot Windows as default until selecting Ubuntu deliberately?

Manual Way

This tip explains very simple steps to make GRUB boot last saved (last used) boot entry:

1. Open /etc/default/grub file to modify:
sudo vi /etc/default/grub

2. Change GRUB_DEFAULT value to 'saved'
GRUB_DEFAULT=saved

3. Add a new variable GRUB_SAVEDEFAULT:
GRUB_SAVEDEFAULT=true

4. Update GRUB configuration to reflect these changes:
sudo update-grub

Now, GRUB loader will boot last used entry as default until you select another entry.

Automatic Way


Here is a simple script to do this for you in one-click (gist here):

filename=/etc/default/grub

# Replace GRUB_DEFAULT value to 'saved'
echo :: Setting GRUB_DEFAULT=saved
sudo sed -i 's/GRUB_DEFAULT=.*/GRUB_DEFAULT=saved/g' $filename

# Append GRUB_SAVEDEFAULT=true after deleting old GRUB_SAVEDEFAULT's
echo :: Setting GRUB_SAVEDEFAULT=true
sudo sed -i '/GRUB_SAVEDEFAULT=.*/d' $filename
sudo sed -i '$aGRUB_SAVEDEFAULT=true' $filename

# Update config
echo :: Calling update-grub
sudo update-grub

WSO2 ESB + ClientAccesPolicy.xml + CrossDomain.xml

ClientAccesPolicy.xml and CrossDomain.xml files have to be found at root of your services Silverlight and Flex clients to be able to acce...