Posts Tagged ‘script’

Determining own directory path in unix bash script

August 12, 2011

In a unix bash script, you can determine the scripts filesystem location by using

SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"

This is especially useful if you want to use “relative” (well, sort of) paths within your script, regardless of which directory the script is being executed from, e.g.

java -jar $SCRIPT_DIR/libs/some-file.jar

If you just used libs/some-file.jar the bash script would only work when executed from the directory it is located in.

Cancellable startup script for Windows

August 12, 2011

Tired of starting all the programs you need after booting your computer day by day? Yay, just create shortcuts to all of them in the Startup directory, Windows will take care of starting them.

So well, works fine… as long as everything else is fine. For most people in IT, it is just a matter of time until there is a more or less urgent emergency to be fixed ASAP (e.g. fixing a web application that has crashed). Here you go: Argh, just wanted to connect to the server and fix the problem, but the computer is more or less unresponsive due to 20 programs starting at the same time. Sorry users, you will have to wait some minutes until my computer decides to be cooperative again. It would be great if one could avoid auto starting if needed.

Batch script to the rescue: The following script waits about 10 seconds before it begins to start the programs, giving you an option to cancel it.

Put the following batch script anywhere on your computer, create a new folder personal-autostart next to it, and put shortcuts to any programs you want to automatically startup with Windows into this folder. Then just add a shortcut to the batch script to the windows startup directory.


@Echo off
echo Personal startup script - hit Strg+C to cancel
echo ##############################################
echo Will start in about 10 seconds:
for %%i in ("personal-autostart\*") do echo %%i
echo ##############################################
echo Personal startup script - hit Strg+C to cancel

@ping 127.0.0.1 -n 10 -w 1000 > nul
for %%i in ("personal-autostart\*") do "%%i"