Conditional Statements inside Batch

I need to create some statements inside a batch file that is similiar to the following:

Set Jobname = %1

If the jobname contains "Weekly" and today is Sunday then

set WaitFile=E:\Console\Nightly_Finished_TodaysDate.txt
Call GenerateFile

If the jobname contains "Static" and today is Sunday then

set WaitFile=E:\Console\Weekly_Finished_TodaysDate.txt
Call GenerateFile

If the jobname contains "Nightly" then
set WaitFile=E:\Console\ALog_Finished_TodayDate.txt
Call GenerateFile

If the jobname contains "Validate" and today is Saturday then

set WaitFile=E:\Console\Nightly_Finished_TodayDate.txt

Call GenerateFile




:GenerateFile

@echo off

:loop
sleep 1
if not exist "%WaitFile%" goto loop
REM Additional code below here ..



Can anyone assist or offer a better way to handle?
earngreenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sirbountyCommented:
opposed to a vbscript solution?
It's possible in a batch file to grab the day's name, but cumbersome...
0
earngreenAuthor Commented:
Not oposed to vbscript
0
sirbountyCommented:
Not sure what your script does beyond this, but this would be the start of it...let me know if you'd like the rest of the batch included here...
Jobname = lcase(wscript.arguments(0))
Today = lcase(WeekdayName(Weekday(Date))
TodayDate = Year(Date) & Month(Date) & Day(Date)
WaitFolder = "E:\Console\"
If Jobname = "" Then wscript.quit
 
Dim objShell : Set objShell = CreateObject("Wscript.Shell")
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
 
If Instr(Jobname, "weekly") > 0 And Today="sunday" Then
  WaitFile="Nightly_Finished_TodaysDate.txt"
ElseIf Instr(Jobname,"static") > 0 And Today="sunday" Then
  WaitFile="Weekly_Finished_TodaysDate.txt"
ElseIf Instr(Jobname,"nightly") > 0 Then
  WaitFile=""ALog_Finished_TodayDate.txt"
ElseIf Instr(Jobname,"validate") > 0 And Today="saturday" Then
  WaitFile="Nightly_Finished_TodayDate.txt"
End If
WaitFile = WaitFolder & Replace(WaitFile, "TodayDate", TodayDate)
 
wscript.sleep 1000
 
If Not objFSO.FileExists(WaitFile) Then
 'do something...
End If

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

earngreenAuthor Commented:
The rest of the batch is just inserting a record into a database similiar to this
Set CN = CreateObject("ADODB.Connection")

CNString = "Driver={SQL Server}; Server=; Database=; UID=; PWD="
CN.ConnectionString = CNString
CN.Open
StrsqlQry = "INSERT INTO Job(Jobname, 'TodaysDate(dd/mm/yy hh:mm:ss)', 'Started','') values(StartTime,JobName,Status,EndTime)"
cn.execute StrsqlQry

The only question that I have with your code(Jobname = lcase(wscript.arguments(0))
) accept a parameter in the same manner as %1 for batch.

The last thiing is there a way to do a check with the sleep function that this fails after n hours of checking for the file


0
sirbountyCommented:
Yes, it takes the first argument (similar to %1) and converts it to lowercase for comparison.

For the checking, you could do something like:
(will basically wait for 30 minutes)

For x = 0 to 120
  wscript.sleep 15000  'sleep 15 seconds before retesting
  If objFSO.FileExists(WaitFile) Then Exit For
Next

0
earngreenAuthor Commented:
This does not seem to want to call the argument. When i run from command line it just does nothing.
0
earngreenAuthor Commented:
Figured it out. Thanks for the help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.