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

Linux


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
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

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


Code:
#!/bin/sh
#get instance id - used for putting metric
INSTANCE_ID=`GET http://169.254.169.254/latest/meta-data/instance-id`

#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[@]}
    do
    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
done

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

10X

Last edited by DukeNuke2; 12-04-2011 at 03:19 AM..
Sponsored Links
    #2  
Old 12-06-2011
Corona688 Corona688 is online now Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 19 September 2014, 1:22 PM EDT
Location: Saskatchewan
Posts: 19,375
Thanks: 789
Thanked 3,267 Times in 3,062 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
    #3  
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 02:30 PM.. Reason: semantics...
    #4  
Old 12-06-2011
methyl methyl is offline Forum Advisor  
Advisor
 
Join Date: Mar 2008
Last Activity: 18 April 2014, 5:13 AM EDT
Posts: 6,396
Thanks: 287
Thanked 672 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
    #5  
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 :

@ECHO OFF
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%"
IF NOT EXIST "%PHP_BIN%" GOTO :PHP_BIN_NOT_INSTALLED
IF NOT EXIST "%WWW_RUN_FILE%" GOTO :WWW_RUN_FILE_NOT_INSTALLED
GOTO :RUN
:PHP_BIN_NOT_INSTALLED
ECHO %PHP_BIN% does not exist
REM GOTO :END
:WWW_RUN_FILE_NOT_INSTALLED
ECHO %WWW_RUN_FILE% does not exist
REM GOTO :END
:RUN
"%PHP_BIN%" -c "%PHP_INI%" -f "%WWW_RUN_FILE%"
pause
REM GOTO :END
:END
@ECHO ON
Please help,
Sponsored Links
    #6  
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
Quote:
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
    #7  
Old 01-19-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 10:30 PM
Txt to csv convert john_prince Shell Programming and Scripting 14 09-15-2009 11:42 AM
how to convert XLS to CSV and DOC/RTF to TXT prvnrk Shell Programming and Scripting 1 04-23-2009 02:47 PM
here-doc convert 2 script convert to single script? yongho Shell Programming and Scripting 2 07-07-2005 04:14 PM
convert from ksh to bsh Boyd Young UNIX for Dummies Questions & Answers 2 01-10-2001 11:58 AM



All times are GMT -4. The time now is 01:51 PM.