ruelle
I have a LAN with 4 PCs and one Synology server. I wish that every time a computer is turned off, it runs a batch (from windows pc) and see if other PCs are on, - if any is on do nothing, - otherwise runs a command that shuts down the server.
Here is what I have at the moment:
Code: Select all
@echo off
PING 192.168.1.10
IF %ERRORLEVEL% EQU 1 plink root@192.168.1.10 -pw MYPASSWORD poweroff
THANK YOU!!
----------------------------
#2 04 Feb 2015 16:49
bluesxman
You can do something like this (untested)...
Code: Select all
@echo off
REM list of all PCs to poll (must include this one)
set "PC_LIST=192.168.0.1 192.168.0.2 192.168.0.3 192.168.0.4"
set "COUNT=0"
for %%I in (%IP_LIST%) do (
REM ping each IP and count how many are responding
ping -n 2 -w 500 %%I | findstr "Reply.*from.*bytes.*TTL" >nul
if not errorlevel 1 set /a COUNT+=1
)
REM take away one, for the PC this is running from
set /a COUNT=-1
echo Found %COUNT% other PC(s) running
if %COUNT% EQU 0 (
echo Shutting down server...
plink root@192.168.1.10 -pw MYPASSWORD poweroff
)
echo Shutting down (use "shutdown -a" to abort)...
shutdown -s -f -t 15
----------------------------
#3 04 Feb 2015 17:18
foxidrive
Does anyone else think it is rude to post the same question to 27 different forums and not mention that you have done so?
https://www.dostips.com/forum/viewtopic.php?f=3&t=6245
----------------------------
#4 04 Feb 2015 20:28
Simon Sheppard
The normal etiquette is to post a link to the other discussions so that people don't end up repeating the same things.foxidrive wrote:
Does anyone else think it is rude to post the same question to 27 different forums and not mention that you have done so?
https://www.dostips.com/forum/viewtopic.php?f=3&t=6245
What I think is worse is when people just post and run, and never return to say if they found an answer.
Saying that a good question can still have value, over time there will be hundreds of people reading this page, if the answers help those people it doesn't matter quite so much if the original poster disappears never to return.
(If anyone wants a fuller discussion about how we should handle posts like this, should we delete them etc, do open a separate thread over on the META forum)
----------------------------
#5 04 Feb 2015 23:46
ruella
https://ss64.org/viewtopic.php?f=2&t=52
https://stackoverflow.com/questions/283 ... -online-pc
https://www.msfn.org/board/topic/173438 ... th-server/
https://www.dostips.com/forum/viewtopic.php?f=3&t=6245
I think last one will be more easy to use thank you for the answer!
sorry for crossposting!! wink
Code: Select all
@echo off
set "flag="
ping 192.168.1.1 -n 2 |find /i "TTL=" >nul && set flag=1
ping 192.168.1.2 -n 2 |find /i "TTL=" >nul && set flag=1
ping 192.168.1.3 -n 2 |find /i "TTL=" >nul && set flag=1
ping 192.168.1.4 -n 2 |find /i "TTL=" >nul && set flag=1
if not defined flag echo shutdown server
#6 04 Feb 2015 23:54
ruella
also crossposted here
https://forum.synology.com/enu/viewtopi ... 45&t=96609
----------------------------
#7 05 Feb 2015 06:54
foxidrive
That's trueSimon Sheppard wrote:
over time there will be hundreds of people reading this page, if the answers help those people it doesn't matter quite so much
This documentary has a quote which agrees too:
In The Wrath of Khan (1982), Spock says, “Logic clearly dictates that the needs of the many outweigh the needs of the few.”
----------------------------
#8 06 Feb 2015 00:05
Simon Sheppard
If you can use PowerShell, this ping function will only return $True if the pings to ALL the machines succeed. Based on that you can write a one liner IF command to shutdown.
----------------------------