convert .sh to .bat | Unix Linux Forums | Linux

  Go Back    

Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

convert .sh to .bat


Closed Thread    
Thread Tools Search this Thread Display Modes
Old 12-04-2011
aviramshl aviramshl is offline
Registered User
Join Date: Dec 2011
Last Activity: 5 December 2011, 5:24 AM EST
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
convert .sh to .bat

I need help to make a. Sh to bat.
Here's the code

#get instance id - used for putting metric

#belowshould be changed to grep - get only everything after % space slash
filesystemlist=`df -l | grep -i \/ | cut -c57-100` #add -l to restrict to local file systems

for filesystemmountpoint in ${filesystemlist[@]}
    storageused=`df | grep %\ *$filesystemmountpoint$ | grep -o [0-9]*% | tr -d %` #need to error check and possibly remove leading white space
    mon-put-data --metric-name StorageUsed --namespace EC2/Storage --value $storageused --unit Percent --dimensions FileSystem=$filesystemmountpoint,InstanceId=$INSTANCE_ID

#to run in cron every 5 minutes as root user - ideally would be run as a limited access user
#echo "*/5 * * * * root /root/" > /etc/cron.d/ec2-write-storage-used


Last edited by DukeNuke2; 12-04-2011 at 04:19 AM..
Sponsored Links
Old 12-06-2011
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
Join Date: Aug 2005
Last Activity: 30 January 2015, 5:59 PM EST
Location: Saskatchewan
Posts: 20,192
Thanks: 862
Thanked 3,511 Times in 3,279 Posts
You can't just "convert sh to bat". Windows doesn't have anything close to the same syntax for many things. A direct translation wouldn't even be useful, since Windows doesn't have any of the same commands.

It doesn't have "GET". You might be able to get a windows version of curl to replace it with.

It doesn't have backticks to put GET inside.

It doesn't have arrays.

It doesn't have df. It doesn't even have proper mountpoints, which makes getting anything like df difficult.

It doesn't have mon-put-data, whatever that is.

You'll need to write something new from scratch.
Sponsored Links
Old 12-06-2011
curleb curleb is offline Forum Advisor  
Registered User
Join Date: Mar 2008
Last Activity: 23 September 2013, 4:29 PM EDT
Location: Surrounded...
Posts: 383
Thanks: 1
Thanked 28 Times in 27 Posts
You might want to look into getting either a shell emulation, such as U/Win or Cygwin, which might allow you to shorten the development curve somewhat, while still using your original code/logic. Otherwise, you'll probably need to adapt the existing code to another syntax, such as a scripting language of your choice (ie, Perl or something like that), which can run on Windows...but would be "from scratch" as Corona688 has said.

You could also just set up a virtualization host on the new Windows machine, and lay down the original OS/shell configuration...and just pretend like none of this ever happened.

Last edited by curleb; 12-06-2011 at 03:30 PM.. Reason: semantics...
Old 12-06-2011
methyl methyl is offline Forum Advisor  
Join Date: Mar 2008
Last Activity: 26 December 2014, 10:07 PM EST
Posts: 6,396
Thanks: 287
Thanked 673 Times in 642 Posts
This does not in any way constitute a recommendation.

If you install the "Microsoft Windows Script Host" you have at your fingertips a powerful Microsoft scripting language of the quality we expect from Microsoft (backup your computer and install all Microsoft Service Packs before using the software). It may not be easy, but the conversion may well be possible by rewriting the original Shellscript from scratch.
Sponsored Links
Old 12-13-2011
Christopher37 Christopher37 is offline
Registered User
Join Date: Dec 2011
Last Activity: 14 December 2011, 5:56 AM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
I have to convert the following .bat code in the .sh code :

REM Checking necessary files
SET "PHP_BIN=C:\Program Files\xampp\php\php.exe"
SET "PHP_RUN_FILE=user_integration.php"
SET "WWW_DOCUMENT_ROOT=C:\moodle\server\moodle"
SET "PHP_INI=C:\Program Files\xampp\php\php.ini"
SET "WWW_RUN_FILE=%WWW_DOCUMENT_ROOT%\batch\user_integration\%PHP_RUN_FILE%"
ECHO %PHP_BIN% does not exist
ECHO %WWW_RUN_FILE% does not exist
"%PHP_BIN%" -c "%PHP_INI%" -f "%WWW_RUN_FILE%"
Please help,
Sponsored Links
Old 12-15-2011
Deluge's Avatar
Deluge Deluge is offline
Registered User
Join Date: May 2010
Last Activity: 25 August 2014, 2:13 PM EDT
Posts: 18
Thanks: 1
Thanked 2 Times in 2 Posts
Originally Posted by curleb View Post
You might want to look into getting either a shell emulation, such as U/Win or Cygwin
MSYS (Minimal System) is another one. I use it quite a bit and like it.
Sponsored Links
Old 01-20-2012
03sep2011 03sep2011 is offline
Registered User
Join Date: Jan 2012
Last Activity: 22 January 2012, 3:03 AM EST
Posts: 8
Thanks: 0
Thanked 1 Time in 1 Post
Better use cygwin, that is a better alternative
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Convert / to \ magesh_bala Shell Programming and Scripting 4 10-27-2010 11:30 PM
Txt to csv convert john_prince Shell Programming and Scripting 14 09-15-2009 12:42 PM
how to convert XLS to CSV and DOC/RTF to TXT prvnrk Shell Programming and Scripting 1 04-23-2009 03:47 PM
here-doc convert 2 script convert to single script? yongho Shell Programming and Scripting 2 07-07-2005 05:14 PM
convert from ksh to bsh Boyd Young UNIX for Dummies Questions & Answers 2 01-10-2001 12:58 PM

All times are GMT -4. The time now is 09:45 PM.