LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 04-05-2011, 08:59 AM   #1
aullah
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Rep: Reputation: 0
Batch file conversion to shell script


I know it's not a new topic, but still I am opening this thread.Can anyone help me to convert this windows batch file to shell script ? I am very new to shell and trying to learn but still I need some help from experts. I'll be glad if someone can help me in this matter/

@ECHO OFF
REM Event Rule Batch Script run by Secure FTP Server On Successful File Upload
REM %1 = filename
REM %2 = username
REM %3 = stream (ServU-FTP, SERVU-SSL, FTPSSH-SSH)

SETLOCAL

REM CHANGING DRIVE TO %~D1
%~D1

REM get file time & date stamp
for /f "tokens=2" %%I in ('date /t') do for /f "delims=/- tokens=1,2" %%J in ("%%I") do set MD=%%J%%K
for /f "delims=: tokens=1,2" %%I in ('time /t') do set HM=%%I%%J
REM SET TS=%MD%%HM: =0%.%3
for /f %%I in ('e:\xedi\utils\gettime.exe') do set TS=%%I

SET FILEPATH=%~p1
SET FILENAME=%~nx1
SET FILEDATE=%~t1
SET FILESIZE=%~z1
SET USERNAME=%2

REM ======= Customer uses their own file uploading rules ===========
IF /i "%2"=="SonyElect" GOTO SONYELECT
IF /i "%2"=="YAMAHA" GOTO YAMAHA
IF /i "%2"=="YamahaSSH" GOTO YAMAHA
IF /i "%2"=="YamahaSSHtest" GOTO YAMAHA
REM =============================================================

GOTO END

REM =========================================================================
:SONYELECT
REM =========================================================================

e:\xedi\utils\sleep 2
IF EXIST *.DAT move \XEDI\USER\SonyElect\*.DAT \xedi\run\inbound\"%3^%2^%1^%TS%" || echo ERROR on %TS%: Failed moving %2 - %1 file upon successful Upload >> \xedi\flg\OnFileUploadRule.err
GOTO END

REM =========================================================================
:YAMAHA
REM =========================================================================

e:\xedi\utils\sleep 2
move %1 \xedi\run\inbound\"%3^%2^%1^%TS%" || echo ERROR on %TS%: Failed moving %2 - %1 file upon successful rename >> \xedi\flg\OnFileRenameRule.err
GOTO END

REM =========================================================================
:END
REM =========================================================================

SET TS=
SET MD=
SET HM=

SET FILEPATH=
SET FILENAME=
SET FILEDATE=
SET FILESIZE=
SET USERNAME=

ENDLOCAL
 
Old 04-05-2011, 09:03 AM   #2
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
Hello and Welcome to LinuxQuestions,

You can easily convert most of it yourself with the help of this table. Start by changing the obvious, try it out and let us know where you need more help or where it's failing.

Kind regards,

Eric
 
Old 08-16-2011, 03:00 AM   #3
salemeni
Member
 
Registered: Aug 2011
Posts: 64

Rep: Reputation: Disabled
Post

Quote:
Originally Posted by aullah View Post
I know it's not a new topic, but still I am opening this thread.Can anyone help me to convert this windows batch file to shell script ? I am very new to shell and trying to learn but still I need some help from experts. I'll be glad if someone can help me in this matter/

@ECHO OFF
REM Event Rule Batch Script run by Secure FTP Server On Successful File Upload
REM %1 = filename
REM %2 = username
REM %3 = stream (ServU-FTP, SERVU-SSL, FTPSSH-SSH)

SETLOCAL

REM CHANGING DRIVE TO %~D1
%~D1

REM get file time & date stamp
for /f "tokens=2" %%I in ('date /t') do for /f "delims=/- tokens=1,2" %%J in ("%%I") do set MD=%%J%%K
for /f "delims=: tokens=1,2" %%I in ('time /t') do set HM=%%I%%J
REM SET TS=%MD%%HM: =0%.%3
for /f %%I in ('e:\xedi\utils\gettime.exe') do set TS=%%I

SET FILEPATH=%~p1
SET FILENAME=%~nx1
SET FILEDATE=%~t1
SET FILESIZE=%~z1
SET USERNAME=%2

REM ======= Customer uses their own file uploading rules ===========
IF /i "%2"=="SonyElect" GOTO SONYELECT
IF /i "%2"=="YAMAHA" GOTO YAMAHA
IF /i "%2"=="YamahaSSH" GOTO YAMAHA
IF /i "%2"=="YamahaSSHtest" GOTO YAMAHA
REM =============================================================

GOTO END

REM =========================================================================
:SONYELECT
REM =========================================================================

e:\xedi\utils\sleep 2
IF EXIST *.DAT move \XEDI\USER\SonyElect\*.DAT \xedi\run\inbound\"%3^%2^%1^%TS%" || echo ERROR on %TS%: Failed moving %2 - %1 file upon successful Upload >> \xedi\flg\OnFileUploadRule.err
GOTO END

REM =========================================================================
:YAMAHA
REM =========================================================================

e:\xedi\utils\sleep 2
move %1 \xedi\run\inbound\"%3^%2^%1^%TS%" || echo ERROR on %TS%: Failed moving %2 - %1 file upon successful rename >> \xedi\flg\OnFileRenameRule.err
GOTO END

REM =========================================================================
:END
REM =========================================================================

SET TS=
SET MD=
SET HM=

SET FILEPATH=
SET FILENAME=
SET FILEDATE=
SET FILESIZE=
SET USERNAME=

ENDLOCAL
You must explain that this script do.
Make a description of this script.

generics array

Last edited by salemeni; 12-06-2011 at 02:58 AM.
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
any shell script 2 batch file tools? rosbur Linux - General 10 08-04-2012 09:48 AM
Need to convert a batch file to a shell script webshore Linux - Newbie 2 05-03-2010 07:42 AM
Executing a batch file on Windows from Linux using a Shell-Script paragkalra Linux - Networking 3 08-13-2008 12:45 PM
Change batch script to shell script alan.belizario Programming 5 03-31-2005 12:41 AM
Help w/ batch/shell script mikehlinuxquest Linux - General 5 09-13-2004 04:41 PM


All times are GMT -5. The time now is 02:12 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration