I'm making several batch scripts which should check if a remote PC is online before executing both commands in the script, and if it fails any of the checks to make a blank file with the "_failed" added to the log file name, which in turn triggers a failed backup notification e-mail via a File screen rule on the server.
The script I put together from several sources goes as follows (and is actually working pretty well so far):
IF EXIST "\\192.168.121.2\c$" (
robocopy "\\192.168.121.2\c$\MLINCK" "D:\Store\ProgressULJ" *.* /mir /copyall /zb /np /xf lbia*.* rcda*.* srta*.* dbi*.* *.lk /r:2 /log+:"C:\Logs\Sync-progressULJ_%DATE:~7,2%_%DATE:~4,2%_%DATE:~12,2%.txt") else (type NUL > C:\Logs\Sync-progressULJ_%DATE:~7,2%_%DATE:~4,2%_%DATE:~12,2%_failed.txt
)
IF EXIST "\\192.168.121.2\c$" (
7za a -tzip "D:\Daily\ProgressULJ_%DATE:~7,2%_%DATE:~4,2%_%DATE:~12,2%.zip" "D:\Store\ProgressULJ\*" -mx=5) else (type NUL > C:\Logs\Sync-progressULJ_%DATE:~7,2%_%DATE:~4,2%_%DATE:~12,2%_failed.txt
)
The issue I keep having with it is that the script creates failed logs despite the script normally going through it's actions when the host is online. When the host in question is offline, the script just dumps the empty log file and that's it, like it should. When the host is online, the script does its stuff and still makes the fail log, which triggers false alarms via email, but I can't see what I'm doing wrong.
I tried the if ping version of the script (which is pretty common here) but it wasn't working as good as the if exist loop version, as this one kicks off immediately if the remote PC is on, but it still does a few checks if it can't connect to it immediately before skipping the command.
Aucun commentaire:
Enregistrer un commentaire