Link to home
Start Free TrialLog in
Avatar of mokkan
mokkan

asked on

Windows batch script from unix bash

I am not a windows guy and I need to convert the following script to windows batch.


LOCKFILE=/tmp/$LOCKFILE
case "$1" in
start)
    touch $LOCKFILE
    poweron.sh;;
    exit 0;
stop)
    rm $LOCKFILE  
    poweroff.sh;;
    exit 0;
    ;;
monitor)
    if [ -a $LOCKFILE ]
    then
        exit 110
    else
        exit 100
    fi ;;
*)
    echo "Usage: $0 {start|stop|monitor} lock_file
    exit 1
    ;;
esac
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

What you posted just looks like an init script for two other scripts.

What does poweron.sh and poweroff.sh do?
Avatar of mokkan

ASKER

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\\filename.id";

if (-f "$LockFile") {
      exit(500);
} else {
      exit(600);
}
Avatar of mokkan

ASKER

any help
I would recommend not even looking at batch files and going right for a powershell or vbs script.

A rough untested conversion might be:
$LOCKFILE=$args[1]
switch ($args[0]) {
    "start" {
        set-content -Path ($LOCKFILE) -Value ($null)
        ./poweron.ps1
    }
    "stop" {
        Remove-Item $LOCKFILE   
        ./poweroff.ps1
    }
    "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.
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mokkan

ASKER

Thank  you