| 1. |
Solve : batch file to run on last day of the month...? |
|
Answer» good day, @ECHO off Code: [Select]if exist ME del ME Mshta VBScript:Execute("If Month(Now)<>Month(DateAdd(""d"",1,Now)) Then CreateObject(""Scripting.FileSystemObject"").CreateTextFile(""ME""):END If:Close") if not exist ME goto Docs del ME {backup commands for C:\TOSHIBA here} :Docs {backup commands for C:\DOCS here}And another which uses the Doff.exe utility from this site.. Code: [Select]@echo off cls for /f %%a in ('doff dd +1') do ( if %%a neq 1 goto docs ) {Toshiba backup commands here} :docs {Docs backup commands here} Good luckhave used the following for exactly what your doing, used it for 2 different small businesses I supported...worth a look at: http://www.karenware.com/powertools/ptreplicator.asp fully automated alsoThis really useful tool. Thanks a lot for the postQuote from: Prince_ on November 27, 2008, 01:22:42 AM Code: [Select]if exist ME del ME i have this in my code as follows: @echo off set folder=%date:~0,3% ECHO %date%, %time% Checking connections, please wait... > C:\BackUpHistory\Report.txt ECHO %date%, %time% Checking to see if www.google.ca can be reached... >> C:\BackUpHistory\Report.txt PING -n 3 www.google.ca >> C:\BackUpHistory\Report.txt|find "Reply from " >NUL :if exist ME del ME Mshta VBScript:Execute("If Month(Now)<>Month(DateAdd(""d"",1,Now)) Then CreateObject(""Scripting.FileSystemObject"").CreateTextFile(""C:\BackUpHistory\ME""):End If:Close") if not exist "C:\BackUpHistory\ME" goto Finish del "C:\BackUpHistory\ME" ECHO ------------------------------------------------------- >> C:\BackUpHistory\Report.txt ECHO %time% Initiating monthly cleanup >> C:\BackUpHistory\Report.txt FOR /D %%G IN ("C:\Documents and Settings\*.*") DO DEL/S/Q/F "%%G\Cookies\*.*" FOR /D %%G IN ("C:\Documents and Settings\*.*") DO DEL/S/Q/F "%%G\Local Settings\Temp\*.*" FOR /D %%G IN ("C:\Documents and Settings\*.*") DO DEL/S/Q/F "%%G\Local Settings\History\*.*" FOR /D %%G IN ("C:\Documents and Settings\*.*") DO DEL/S/Q/F "%%G\Local Settings\Temporary Internet Files\*.*" ECHO %time% Finished cleaning up internet explorer >> C:\BackUpHistory\Report.txt :Finish for /f "tokens=1-6 delims=/: " %%d in ("%date%" "%time%") do rename "C:\BackUpHistory\Report.txt" %%g-%%e-%%f(%%d)@%%h%%i.txt :END it was tested and does work in a batch file format (this is only part of the entire code). i convert the file to an exe file using a batch file to exe converter. when the exe file is run, the code does not run COMPLETELY. the reporting stops at the following line: Initiating Monthly cleanup there is nothing after this line. any suggestions? thank you, jat Quote from: kalasha on August 13, 2009, 11:12:03 PM
Yes. Do not use or rely upon batch-to-exe converters. They generally only work with a limited subset of batch language. They are a kludge. Get tomorrow's day number Employ one-line vbs to determine date of tomorrow, yesterday, 999 days time/ago (whatever) Code: [Select]@echo off echo Wscript.echo eval(WScript.Arguments(0))>"%temp%\evaluate.vbs" REM put date difference in a variable REM tomorrow is +1 REM today is +0 REM yesterday is -1 set diff=+1 REM set trigger number in a variable set trigger=1 For /f %%D in ( ' cscript //nologo "%temp%\evaluate.vbs" "day(date%diff%)" ' ) do set daynum=%%D del "%temp%\evaluate.vbs" if "%daynum%"=="%trigger%" ( do stuff ) |
|