LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Windows Batch to Unix Shell script (https://www.linuxquestions.org/questions/linux-newbie-8/windows-batch-to-unix-shell-script-937901/)

andreas215 04-03-2012 08:57 AM

Windows Batch to Unix Shell script
 
I needed to make a windows batch file for school. I made an alarm clock that opens windows media player and plays a file and closes it after the file has finished playing. Now I need to make the same thing but in Shell script. I know nothing about Unix Shell script. Can someone please help me to convert this batch file to a shell script?
The Batch file looks like this:

CLS
@echo off
color f0
title Batch Alarm Clock
echo.
echo.
echo Use 24-hour clock
echo.
echo.
set /p a=Set alarm:
CLS
echo.
echo.
echo Alarm has set to %a%.
:alarm
if %time:~0,5% EQU %a% goto alarmset
goto alarm
:alarmset
start wmplayer /play /close "c:\Users\Andreas\Music\alarm.mp3"
# TIMEOUT is the duration of the song and after that the taskkill closes windows media player
TIMEOUT /T 231
taskkill /im wmplayer.exe

TB0ne 04-03-2012 09:59 AM

Quote:

Originally Posted by andreas215 (Post 4643653)
I needed to make a windows batch file for school. I made an alarm clock that opens windows media player and plays a file and closes it after the file has finished playing. Now I need to make the same thing but in Shell script. I know nothing about Unix Shell script. Can someone please help me to convert this batch file to a shell script?
The Batch file looks like this:

We can HELP you, but we're not going to write it FOR YOU. Post what you've done so far, and where you're stuck, and we'll be happy to assist.

Best suggestion I could make, is to walk through the file one line at a time, and identify what each command does, and figure out what the equivalent Linux command is. For example, "CLS" is "clear". Have you tried to look at any of the easily-found bash scripting tutorials?
http://tldp.org/LDP/abs/html/

andreas215 04-03-2012 10:21 AM

This is what I have done so far:

clear
set +v
color f0 Don't know how to change the color, but it isn't important anyway
title Batch Alarm Clock The title isn't important either
echo
echo
echo Use 24-hour clock
echo
echo
export /p a=Set alarm: Replaced "set" with "export" but don't know how to replace the command " /p a=Set alarm: "
clear
echo
echo
echo Alarm has set to %a%. " %a% " is another part that I don't know how to convert
And I don't know how to convert this part from here to the end.
if %time:~0,5% EQU %a% goto alarmset
goto alarm
:alarmset
start wmplayer /play /close "c:\Users\Andreas\Music\alarm.mp3"
TIMEOUT /T 231
taskkill /im wmplayer.exe

TB0ne 04-03-2012 10:49 AM

Quote:

Originally Posted by andreas215 (Post 4643719)
This is what I have done so far:

clear
set +v
color f0 Don't know how to change the color, but it isn't important anyway

Colored text examples:
http://kedar.nitty-witty.com/blog/ho...n-shell-script
Quote:

export /p a=Set alarm: Replaced "set" with "export" but don't know how to replace the command " /p a=Set alarm: "
echo Alarm has set to %a%. " %a% " is another part that I don't know how to convert
And I don't know how to convert this part from here to the end.
if %time:~0,5% EQU %a% goto alarmset
goto alarm
:alarmset
start wmplayer /play /close "c:\Users\Andreas\Music\alarm.mp3"
TIMEOUT /T 231
taskkill /im wmplayer.exe
What are you trying to DO with the /p?? You can look at command-line switches, and (if found) process them. The %a% is a variable...probably going to be replaced with whatever you call the alarm-time variable. And if/while loops are ALL in the scripting guide I posted.

andreas215 04-03-2012 10:52 AM

Ok, thank you, I try to continue converting it when I get back home. I don't remember what the " /p " command did.

David the H. 04-03-2012 12:49 PM

The guide TB0ne linked to even has a whole page specifically on converting batch files to shell scripts.

http://tldp.org/LDP/abs/html/dosbatch.html

Also, please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.

chrism01 04-03-2012 11:55 PM

See also http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html as well as TB0ne's link

stephsanol 07-23-2013 02:33 PM

Batch to Shell script
 
Hi, I'm trying to translate a batch file to shell script but I'm a little stuck with this command:

echo cd /home/opera/SCRIPTS/medios>>tempo
echo pwd>>tempo
echo lcd ../tesoreria>>tempo
echo prompt>>tempo
echo mget *.pag>>tempo
echo mdel *.pag>>tempo

I don't underestand what lcd, mget and mdel commands do here.

Thak you

Firerat 07-23-2013 02:58 PM

Quote:

Originally Posted by stephsanol (Post 4995440)
Hi, I'm trying to translate a batch file to shell script but I'm a little stuck with this command:

echo cd /home/opera/SCRIPTS/medios>>tempo
echo pwd>>tempo
echo lcd ../tesoreria>>tempo
echo prompt>>tempo
echo mget *.pag>>tempo
echo mdel *.pag>>tempo

I don't underestand what lcd, mget and mdel commands do here.

Thak you

It looks like some kind of ftp to me, where lcd is "Local Change Directory"


Does that make sense to you?

flyinggeorge 07-23-2013 09:50 PM

I don't have lcd or mget, but mdel according to the man page is for deleting MSDOS directories recursively.

Z038 07-23-2013 10:24 PM

Quote:

Originally Posted by stephsanol (Post 4995440)
Hi, I'm trying to translate a batch file to shell script but I'm a little stuck with this command:

echo cd /home/opera/SCRIPTS/medios>>tempo
echo pwd>>tempo
echo lcd ../tesoreria>>tempo
echo prompt>>tempo
echo mget *.pag>>tempo
echo mdel *.pag>>tempo

I don't underestand what lcd, mget and mdel commands do here.

Thak you

You should not revive a thread that is more than a year old to post a question that is completely unrelated to the original poster's question. Open your own new thread.

Firerat 07-23-2013 10:30 PM

Quote:

Originally Posted by flyinggeorge (Post 4995601)
I don't have lcd or mget, but mdel according to the man page is for deleting MSDOS directories recursively.

didn't really want to give the game away, but given the context of ftp, mget and mdel are microsoft ftp's internal commands for multiple get and delete.

so to break down what is happening,
ftp to "opera's" computer ( not detailed in the snippet with have )
  1. change to directory /home/opera/SCRIPTS/medios ( on "opera's" computer )
  2. confirm the directory has changed by issuing pwd ( print working directory )
    ( I don't understand why this is useful, if it were a script it would carry on regardless )
  3. change to directory ../tesoreria on local machine
    ( don't ask me why they didn't just start there in the first place, my guess is we only see a small piece of the "script" )
  4. prompt toggle off confirmations
    ( assumes prompt was set on as per default )
  5. get all the files ending with .pag ( from "opera's" computer )
  6. delete all the files ending with .pag ( from "opera's" computer )

anyway, to translate that to Linux, first need to decide on which ftp client, and then learn its commands and scripting format


All times are GMT -5. The time now is 05:37 AM.