LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-03-2012, 09:57 AM   #1
andreas215
LQ Newbie
 
Registered: Apr 2012
Posts: 3

Rep: Reputation: Disabled
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
 
Old 04-03-2012, 10:59 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,933

Rep: Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692
Quote:
Originally Posted by andreas215 View Post
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/
 
Old 04-03-2012, 11:21 AM   #3
andreas215
LQ Newbie
 
Registered: Apr 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
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

Last edited by andreas215; 04-03-2012 at 11:39 AM.
 
Old 04-03-2012, 11:49 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,933

Rep: Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692
Quote:
Originally Posted by andreas215 View Post
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.
 
Old 04-03-2012, 11:52 AM   #5
andreas215
LQ Newbie
 
Registered: Apr 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Ok, thank you, I try to continue converting it when I get back home. I don't remember what the " /p " command did.
 
Old 04-03-2012, 01:49 PM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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.

Last edited by David the H.; 04-03-2012 at 01:53 PM.
 
Old 04-04-2012, 12:55 AM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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
 
Old 07-23-2013, 03:33 PM   #8
stephsanol
LQ Newbie
 
Registered: Jul 2013
Posts: 4

Rep: Reputation: Disabled
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
 
Old 07-23-2013, 03:58 PM   #9
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Quote:
Originally Posted by stephsanol View Post
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?
 
Old 07-23-2013, 10:50 PM   #10
flyinggeorge
Member
 
Registered: Feb 2012
Location: United States
Distribution: Slackware 14.0
Posts: 159

Rep: Reputation: 3
I don't have lcd or mget, but mdel according to the man page is for deleting MSDOS directories recursively.
 
Old 07-23-2013, 11:24 PM   #11
Z038
Member
 
Registered: Jan 2006
Distribution: Slackware
Posts: 835

Rep: Reputation: 165Reputation: 165
Quote:
Originally Posted by stephsanol View Post
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.
 
Old 07-23-2013, 11:30 PM   #12
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Quote:
Originally Posted by flyinggeorge View Post
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

Last edited by Firerat; 07-23-2013 at 11:39 PM. Reason: missed prompt
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Executing a batch file on Windows from Linux using a Shell-Script paragkalra Linux - Networking 3 08-13-2008 01:45 PM
Running Windows batch script from Unix rrguyyala AIX 4 08-26-2007 09:43 AM
telnet windows m/c from unix shell script ann124 Programming 1 11-10-2004 02:26 PM
unix korn shell script that interact with windows java program ann124 Programming 5 11-09-2004 10:14 PM
Help w/ batch/shell script mikehlinuxquest Linux - General 5 09-13-2004 05:41 PM


All times are GMT -5. The time now is 09:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration