Windows batch script  from unix bash

Posted on 2014-02-25
Last Modified: 2014-08-11
I am not a windows guy and I need to convert the following script to windows batch.

case "$1" in
    touch $LOCKFILE;;
    exit 0;
    rm $LOCKFILE;;
    exit 0;
    if [ -a $LOCKFILE ]
        exit 110
        exit 100
    fi ;;
    echo "Usage: $0 {start|stop|monitor} lock_file
    exit 1
Question by:mokkan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39888596
What you posted just looks like an init script for two other scripts.

What does and do?

Author Comment

ID: 39901117
I am trying to learn the batch syntax

Here is a smiple perl script. How do I do it in windows batch?

$LockFile = "C:\\scripts\\";

if (-f "$LockFile") {
} else {

Author Comment

ID: 39901552
any help
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 43

Expert Comment

ID: 39907792
I would recommend not even looking at batch files and going right for a powershell or vbs script.

A rough untested conversion might be:
switch ($args[0]) {
    "start" {
        set-content -Path ($LOCKFILE) -Value ($null)
    "stop" {
        Remove-Item $LOCKFILE   
    "monitor" {
        if (Test-Path $LOCKFILE ) {
            exit 110
        else {
            exit 100
    default {
        "Usage: $0 {start|stop|monitor} lock_file
        exit 1

Open in new window

What context does the script run?  It looks as slightwv says as being an init script.
LVL 77

Accepted Solution

slightwv (䄆 Netminder) earned 500 total points
ID: 39908002
>>Here is a smiple perl script. How do I do it in windows batch?

The -f just checks if a file exists and takes appropriate action.  In the case of the code you posted, it exits with a different return value.

To check if a file exists in a BAT file, it is almost as simple.

An example of this can be found on Microsoft's site at:

None of this will really help unless you answer the question I asked in the first post:
What does and do?

These seem to be the important pieces to the script you posted.

Author Closing Comment

ID: 40254640
Thank  you

Featured Post

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many admins will agree: WSUS is is a nice invention but using it on the client side when updating a newly installed computer is still time consuming as you have to do several reboots and furthermore, the procedure of installing updates, rebooting an…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question