?
Solved

get day of week in dos batch file???

Posted on 2005-03-18
4
Medium Priority
?
20,861 Views
Last Modified: 2012-08-14
Users on my network have a logon script called LOGON.BAT

I want to perform specific processing based upon day of the week.  Basically if the day of the week is Tuesday, Thursday, Saturday, or Sunday I want some specific processing to take place.  If not, just exist.

How can I code my LOGON.BAT file to check for those specific days????
0
Comment
Question by:NEARNG
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 5

Expert Comment

by:brianadkins
ID: 13577227
for /f %%a in ('date /t') do set DAY=%%a

then just check for specific values, I.e.:

if %DAY%=Fri goto :skipprocessing
0
 
LVL 5

Expert Comment

by:brianadkins
ID: 13577276
forgot the double equal sign as a comparator:

----------------8<-------------------------------
for /f %%a in ('date /t') do set DAY=%%a

if %DAY%==Mon goto :skipprocessing
if %DAY%==Wed goto :skipprocessing
if %DAY%==Fri goto :skipprocessing

:: put your processing here

:skipprocessing
----------------8<-------------------------------
0
 

Author Comment

by:NEARNG
ID: 13578043
That worked!!!!  Thanks Brian!

Can I ask you one more question related to this??  I have increased the point value for your efforts.

Desktops on my network all have characters 12 and 13, of their computer name, as WK.

Laptops have an NB for characters 12 and 13.  So, my laptop is ABAB-98989-NBL1.  

What I want is for all laptops to perform the processing no matter what day it is.  This is because laptops "touch" the network at infrequent times.  So, if characters 12 and 13 of the computer name equal to NB...  Perform processing every day.

Desktops can "skipprocessing" on Mon, Wed, and Fri.

Can you help??

Thanks!!!!!!!

Eric
0
 
LVL 5

Accepted Solution

by:
brianadkins earned 1200 total points
ID: 13578761

Something like this should work...  If the 2 chars starting with char 11 are 'NB', just skip ahead and start the processing...

(the character positions begin with zero, so 11,2 should be chars 12 and 13)

the '/i' in the IF command means case insensitive

----------------8<-------------------------------

if /i "%computername:~11,2%"=="NB" goto :process

for /f %%a in ('date /t') do set DAY=%%a
if %DAY%==Mon goto :skipprocessing
if %DAY%==Wed goto :skipprocessing
if %DAY%==Fri goto :skipprocessing

:process
:: put your processing here

:skipprocessing
----------------8<-------------------------------

-Brian
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question