Pages

Showing posts with label scripts. Show all posts
Showing posts with label scripts. Show all posts

Script to enable/disable proxy


To Enable Proxy
EnablePorxy.vbs

set shell = Wscript.CreateObject("Wscript.Shell")
shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 0, "REG_DWORD"


To disable Proxy
DisablePorxy.vbs

set shell = Wscript.CreateObject("Wscript.Shell")
shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 1, "REG_DWORD"


Maven: multiple builds from cmd file

This is just a followup on/refinement of my previous post. This cmd/bat Script focuses on clean-build-installing multiple projects from a single script. This script halts at the first build failure. If you happen to run from window explorer by doble clicking the script, In case of error the command window stays open (Press any key to continue). If ever build was successful, the window closes automatically. In the following example, I am skipping the test execution for third project you can add/remove -DskipTests=true to any mvn calls.

REM Uncomment following if you want to clean local repo on each run
REM rmdir /S /Q "%HOMEPATH%\.m2\repository\com\mygroup\id"

call mvn -f ProjectA\pom.xml clean install
if not "%ERRORLEVEL%" == "0" goto error

call mvn -f ProjectB\pom.xml clean install
if not "%ERRORLEVEL%" == "0" goto error

call mvn -DskipTests=true -f ProjectC\pom.xml clean install
if not "%ERRORLEVEL%" == "0" goto error

exit

:error
@echo Build Failed
pause


Hope you find this helpful.

Reference:
This  question at SO helped.

Calling multiple bat files from a bat file

Earlier I had posted about closing command window that is left open after executing a bat file. This post is about calling multiple bat files from a bat file.

Today, while trying to execute multiple maven builds from a bat file, I observed that only first build one was called and once the first build was over, the execution stopped. Next builds were not called at all. I Did some search and found this. Yeah mvn command is a bat file, I knew that. What i missed was putting a call before the mvn commands:

cd ProjectA
call mvn install
cd ..

cd ProjectB
call mvn install
cd ..


The post linked above goes one level further by checking the %ERRORLEVEL% and exiting the script if any any build fails.

So lesson learnt today :
If you need to call multiple bat files from a bat file, start each bat command with a call

Display System Properties in Groovy

It can't get any simpler than this.

System.properties.each { k,v->
    println "$k = $v"
}

Groovy rocks!!

Closing cmd window after executing bat file

Just a small post you may find useful if you are as annoyed as I was of a command window left open after execution of a bat file.

I had to call an exe with some options. So I wrote a bat for it. But after executing the bat file, it always kept a command window open until I explicitly close it or the executed program finishes. Actually the command window remains open till the control is returned from the exe to bat again. Point to be noted is EXIT doesn't help in this case as it's call is also deferred until control is returned back.

eg.

start-netbeans.bat
netbeans --jdkhome d:\dev\jdk

putty-to-server.bat
d:\programs\putty -pw password username@ip-addrs

Use start before the command so your bat calls the exe and continues its execution i.e. doesn't wait for the exe to complete the execution

start netbeans --jdkhome d:\dev\jdk

start d:\programs\putty -pw password username@ip-addrs

You can use pause command for "Press any key to continue . . ."

Delete data from tables

Ever needed to clear all the data from your database (usually while in development)?
You can use this script to clean the tables. It will work for oracle only, AFAIK.

-- script to clean the tables (ie the deleting the data only)
DECLARE
cursor c1 is select distinct table_name from user_tab_columns;

BEGIN
for v1 in c1 loop
dbms_output.put_line('cleaning '|| v1.table_name ||'...');
execute immediate 'Delete from '|| v1.table_name ||'';
dbms_output.put_line('done');
end loop;
dbms_output.put_line('completed');
END;

Disclaimer: I hold no responsibility for the havoc this script may create on your database ;) never use it on production databases.