Execute command every 5 min off multiple drives
Posted: 08 Apr 2016 10:49
I have some portable drives that I'd like to never spin-down, in other words make them impossible to sleep. The reason for this is to avoid some errors due to drive's firmware which puts the drive in sleep regardless of windows os settings.
Expected result of the script:
For each drive/partition that contains the extensionless file nosleep in its root, execute the command pushd %drvLetter% dir /b /s > tempdata.txt every 5 minutes, non-stop on all found drives.
Incompleted Sample Script:
The following is something similar to what I'm trying to do but can't finish it because it is beyond my current knowledge. Added some REM comments that explains some stuff.
Thank you for your time and patience.
Expected result of the script:
For each drive/partition that contains the extensionless file nosleep in its root, execute the command pushd %drvLetter% dir /b /s > tempdata.txt every 5 minutes, non-stop on all found drives.
Incompleted Sample Script:
The following is something similar to what I'm trying to do but can't finish it because it is beyond my current knowledge. Added some REM comments that explains some stuff.
Code: Select all
REM Set all found drives in a variable
for /f %%a in (c d e f g h i j k l n m o p q r s t u v w x y z) do (
if exist %%a:\nosleep (
set dev=%%a:
)
)
REM loop through each found drive letter in the variable and then loop indefinetaly the same command every 5 min on that drive.
:loop
for /f "delims=;" %%a in (%dev%) do (
pushd %dev%
ping 127.0.0.1 -n 300 > nul
dir /b /s > tempdata.txt
goto loop
)
Thank you for your time and patience.