Operating System - HP-UX
1847384 Members
3441 Online
110264 Solutions
New Discussion

Urgent request to convert batch script to korn shell script

 
Becke
Super Advisor

Urgent request to convert batch script to korn shell script


Hello Team,

I have some small batch scripts which need to be converted into korn shell scripts, can anyone assist me converting these scripts to korn shell. Its pretty urgent

Below is the script called cleanUPLog.bat

@ECHO OFF

:Init
SETLOCAL
SET WebTopSystemName=""
IF /I %COMPUTERNAME%==N00402AP040 SET WebtopSystemName=WAS
IF /I %COMPUTERNAME%==N00402AP041 SET WebtopSystemName=WAS
IF /I %COMPUTERNAME%==N00402AP043 SET WebtopSystemName=WAS
IF /I %COMPUTERNAME%==N00402AP044 SET WebtopSystemName=WAS
IF /I %COMPUTERNAME%==N00402AP045 SET WebtopSystemName=WAS
IF /I %COMPUTERNAME%==N00402AP046 SET WebtopSystemName=WAS
IF /I %COMPUTERNAME%==N00402I0040 SET WebtopSystemName=IHS
IF /I %COMPUTERNAME%==N00402I0041 SET WebtopSystemName=IHS
IF /I %COMPUTERNAME%==N00402I0043 SET WebtopSystemName=IHS
IF /I %COMPUTERNAME%==N00402I0044 SET WebtopSystemName=IHS
IF /I %COMPUTERNAME%==N00402I0045 SET WebtopSystemName=IHS
IF /I %COMPUTERNAME%==N00402I0046 SET WebtopSystemName=IHS
IF %WebtopSystemName%=="" GOTO WrongMachine
SET systemtype=%WebtopSystemName%
SET datedifflimit=%1
SET calledproclib="E:\Applications\Batchfiles\Webtop\Cleanup\"
:CheckforDaysToDeleteparam
IF "%1"=="" (GOTO HOWTOUSE)
IF %systemtype%==WAS SET ArchiveDir=E:\Logs\Webtop\Archive
IF %systemtype%==IHS SET ArchiveDir="E:\logs\IHS\archive"

:START
:GettodaysDateInformation
FOR /f "tokens=2-4 delims=/ " %%a IN ('date /t') DO SET todayfulldate=%%c-%%b-%%a
FOR /f "tokens=2-4 delims=/ " %%a IN ('date /t') DO SET todayyear=%%c
FOR /f "tokens=2-4 delims=/ " %%a IN ('date /t') DO SET todaymonth=%%b
FOR /f "tokens=2-4 delims=/ " %%a IN ('date /t') DO SET todaydate=%%a

:CalculatetodaysDateOffset
SET dateoffsetresult=0
ECHO Todays date is : %todayyear%-%todaymonth%-%todaydate%
CALL %calledproclib%CleanUpOldLogs-calculateDays.bat %todayyear% %todaymonth% %todaydate%
SET todayoffset=%dateoffsetresult%
ECHO Today offset : %todayoffset%

:GetlogsDateInformation
FOR /F %%A IN ('DIR /B /A:-D %ArchiveDir%') DO (
CALL %calledproclib%CleanUpOldLogs-deletelogic.bat %%A
)
GOTO EOF


:WrongMachine
REM ************************************************************************************
REM * *
REM * This script didn't recognise the Computer Name on which it was running. *
REM * It was written to be run on Webtop WAS & IHS Servers only. *
REM * *
REM ************************************************************************************
ECHO !!! ERROR !!!
ECHO *************
ECHO Execution Terminated!
ECHO This script didn't recognise Computer Name %COMPUTERNAME% - Please Inform Webtop Support!!
GOTO EOF

:HOWTOUSE
ECHO ######################################
ECHO # Name : CleanUpOldLogs-main.bat
ECHO #
ECHO # Usage : CleanUpOldLogs-main.bat [system] [number of days of logs to keep]
ECHO # Usage : CleanUpOldLogs-main.bat IHS 20
ECHO # Usage : CleanUpOldLogs-main.bat WAS 5
ECHO # Usage : CleanUpOldLogs-main.bat WAS 1898
ECHO # Notes : [number of days of logs to keep] parameter must be 1 or greater.
ECHO # Notes : If [number of days of logs to keep] == 1, then it WILL delete yesterday's logs.
ECHO # Notes : If [number of days of logs to keep] == 2, then it keep yesterday's logs. Will delete the day before yesterday's logs.
ECHO # Notes : If [number of days of logs to keep] == 0, (special case). Will delete all dated logs. Even if in the future.
ECHO #
ECHO ######################################

:ReturnWithError
ECHO An ERROR has occurred1.
COLOR 00

:EOF
ENDLOCAL

Thanks Heaps.