The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
character set conversion in unix C gucho High Level Programming 1 03-01-2008 05:27 AM
Dos to Unix conversion john413 Shell Programming and Scripting 1 09-10-2005 12:13 PM
Unix to EBCDIC conversion Bab00shka UNIX for Dummies Questions & Answers 2 01-20-2005 09:58 AM
unix to windows conversion misc19432043 Filesystems, Disks and Memory 2 10-10-2002 11:08 PM
Time conversion in Unix kamlakar UNIX for Advanced & Expert Users 1 04-22-2002 09:55 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-10-2005
Registered User
 

Join Date: Aug 2004
Posts: 4
conversion from Unix to windows

Hey guys,

Im looking to convert the following script into batch language for windows / DOS but my knowledge of batch syntax is nill - but i have good knowledge of UNIX shell...can anyone help?


#!/bin/sh

if [ $# -lt 2 ] ; then
echo "UNCERTAIN:"
echo "Too few arguments"
echo "Usage: file_exists <filename> <exists|notexists|contains> [<text_to_search>]"
echo "!!SCRIPT_FINISHED!!"
exit 1
fi

if [ $2 == "exists" ] ; then
if [ -f "$1" ] ; then
echo "TRUE:"
echo "$1 file exists"
else
echo "FALSE:"
echo "$1 file does not exist"
fi
fi

if [ $2 == "notexists" ] ; then
if [ -f "$1" ] ; then
echo "FALSE:"
echo "$1 file exists"
else
echo "TRUE:"
#!/bin/sh

if [ $# -lt 2 ] ; then
echo "UNCERTAIN:"
echo "Too few arguments"
echo "!!SCRIPT_FINISHED!!"
exit 1
fi

if [ $2 == "exists" ] ; then
if [ -f "$1" ] ; then
echo "TRUE:"
echo "$1 file exists"
else
echo "FALSE:"
echo "$1 file does not exist"
fi
fi

if [ $2 == "notexists" ] ; then
if [ -f "$1" ] ; then
echo "FALSE:"
echo "$1 file exists"
else
echo "TRUE:"
echo "$1 file does not exist"
fi
fi

if [ $2 == "contains" ] ; then
if [ -f "$1" ] ; then
TIME=`date|tail -c19|head -c5`
FOUND=`cat $1|grep $TIME|grep $3`
if [[ -n $FOUND ]] ; then
echo "TRUE:"
echo "File $1 contains [$3]"
else
echo "FALSE:"
echo "File $1 does not contain [$3]"
fi
else
echo "FALSE:"
echo "$1 file does not exist"
fi
fi

echo "!!SCRIPT_FINISHED!!"

Thanks josh
Reply With Quote
Forum Sponsor
  #2  
Old 10-10-2005
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
How about installing Cygwin (or Microsoft Services for Unix) on the Windows box.
Reply With Quote
  #3  
Old 10-10-2005
Just Ice's Avatar
Lights on, brain off.
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 629
you can either go with cygwin/msu or you can look at some dos scripting books ... also check "help" and "if /?" on a windows cmd window for pointers on if tests and dos batch scripting ...
Reply With Quote
  #4  
Old 10-10-2005
Registered User
 

Join Date: Jan 2005
Posts: 682
I would chime in with the same response regarding CYGWIN. You can write some very functional DOS/NT scripts but even simple tasks are much tougher to implement. CYGWIN will give you an easier migration path.

If Cygwin can't be used, you start here.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:41 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0