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
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
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);
}
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);
}
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:
What context does the script run? It looks as slightwv says as being an init 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
}
}
What context does the script run? It looks as slightwv says as being an init script.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you
What does poweron.sh and poweroff.sh do?