1.

Solve : How do you pass value from output to input and verify?

Answer»

Could SOMEONE assist me in figuring out how to grab the DAYS value from the systeminfo command, so that it could be tested to be less than 15. And if greater than 15 execute a shutdown -r to reboot the computers/servers???

I want to add this to my scheduled tasks to run daily vs having to manually tell it to execute on specific dates, since the only options are Daily, Weekly, Monthly, in the Task Scheduler of XP Pro and there was no option for bi-weekly which is what I need.

Reason for this scheduled reboot is that the POS software ( POINT Of Sale ...not the other POS meaning ) .... we are running has some sort of memory leak, which causes problems to show up on around the 18th day. And I would rather not reboot the servers daily as this may overstress them, since they run best when running 24/7, but not 24/18 ha ha, so I want them to run 24/15 and reboot to clear the leak.

Below is an output snippet from the systeminfo command that I think would work best for passing the triggering value to the IF command of a batch to test for a value less than 15, THEN shutdown -r if equal to or greater than 15. This would then cause the system/servers to reboot on the 15th day, when the daily scheduled task would run and test this.

I dont know how to grab this value, not sure if the whole output has to be passed to an array, then searched for DAYS in which it would grab the value before it and test with the IF command???

Thanks ... Dave

---------------------------------------------------

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\dlembke>systeminfo

Host Name: FRANKENSTEIN
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 2 Build 2600
OS Manufacturer: Microsoft Corporation
OS Configuration: Member Workstation
OS Build Type: Multiprocessor Free
Registered Owner: cfs
Registered Organization: cfs
Product ID: 76487-015-4615084-22789
Original Install Date: 7/29/2006, 7:06:44 AM
System Up Time: 16 Days, 2 Hours, 14 Minutes, 33 Seconds
System Manufacturer: MICRO-STAR INTL, CO.,LTD.
System Model: MS-7037
System type: X86-based PC
Processor(s): 2 Processor(s) Installed.
[01]: x86 Family 15 Model 4 Stepping 1 GenuineIntel ~
3000 Mhz
[02]: x86 Family 15 Model 4 Stepping 1 GenuineIntel ~
3000 MhzCode: [Select]@echo off
set maxupdays=15
REM 1. Filter the line containing "Up Time" out of
REM systeminfo output & put it in a text file
systeminfo | @find "Up Time" > %temp%\uptime.txt

REM 2. extract first token in comma delimited STRING
for /F "delims=," %%a in (%temp%\uptime.txt) do set string=%%a

REM 3. strip out the characters from the 15th onward
set d=%string:~15,-4%

REM 4. strip leading spaces
call :strip %d%

echo updays=%updays%

REM 5. perform comparison
if %days% GTR %maxupdays% (
echo uptime more than %maxupdays% days
REM etc
REM etc
)
goto :EOF




:strip
set updays=%*
goto :EOF



Contrex's code looks good, EXCEPT I think there might be problems using quotes in the GTR comparison. You may want to change line:
Code: [Select]if "%days%" GTR "%maxupdays%" (to:
Code: [Select]if %days% GTR %maxupdays% (
Also, you CAN add a reboot (SHUTDOWN.EXE) to your scheduled tasks. Choose "Weekly", then it will give you an option to run every X weeks, and you can choose 2 weeks. Or you can choose "Daily" and choose every 15 days.Quote from: GuruGary on May 25, 2007, 03:26:20 PM

Contrex's code looks good, except I think there might be problems using quotes in the GTR comparison.

I got in the habit of using quotes for IF comparisons, I don't seem to have encountered any problems so far. What sort do you envisage? (Always glad to pick up tips). Do you mean because the data is numerical?

I tried that code with dummy data from 1 to 999 and they all worked fine.
Contrex: I might be wrong, and I can't remember for sure. But I think it was something like using quotes (or anything non-numeric) in a numeric comparison (GTR, GEQ, etc.) changes the comparison to text / alphabetical comparison instead of a numeric comparison. If that was the case then 10 < 2 because 1 < 2. Does that make sense?

Let me know if I didn't explain it well, but basically I think it is an ASCII vs numeric comparison issue.Quote from: DaveLembke on May 25, 2007, 10:41:53 AM
....there was no option for bi-weekly which is what I need.

I thought there is? you choose weekly task, then on the next screen, there's option for you to specify how many weeks and which day. but correct me if i am wrong though..
Quote from: GuruGary on May 25, 2007, 03:26:20 PM
Also, you CAN add a reboot (SHUTDOWN.EXE) to your scheduled tasks. Choose "Weekly", then it will give you an option to run every X weeks, and you can choose 2 weeks. Or you can choose "Daily" and choose every 15 days.
Quote from: GuruGary on May 25, 2007, 07:30:33 PM
I think it is an ASCII vs numeric comparison issue.

Code: [Select]c:\>set num1=10

c:\>set num2=2

c:\>if %num1% GTR %num2% echo %num1% is greater than %num2%
10 is greater than 2

c:\>if "%num1%" GTR "%num2%" echo %num1% is greater than %num2%

c:\>

Exactly right. Thanks for the hint.
Streamlined version, no temp file, no labels, shutdown in 10 seconds, force running apps to close
without warning.

You may want to modify shutdown behaviour, add more lines, etc, this is just an example
Code: [Select]set maxupdays=14
for /f "tokens=2,3,4* delims= " %%a in ('systeminfo ^| @find "Up Time"') do set updays=%%c
if %updays% GTR %maxupdays% (
shutdown -r -t 10 -f -c "Scheduled restart in 10 seconds"
)






Many Thanks Contrex!!!

This works well. I also edited my shutdown to be more specific like you suggested, just in case something wants to STAY open hanging the reboot.

Dave


Discussion

No Comment Found