• 0

Windows WakOnLAN batch script


Question

I currently have a script to encode files and send them to another machine over the LAN. I've started putting the remote machine to sleep since it isn't being used as much, so I want the batch file to wake the machine if needed.

What I'd like to do is:

1. check to see if the PC is currently on

2. encode the files

3. if PC was already on, send periodic packets to keep it on while the script is running

4. run renamer

5. if machine is off, send a magic packet to wake the machine so they can be copied over

6. if need be, wait for machine to turn on, then check it again

7. copy and move files

That way, the machine won't go to sleep while the script is running only to be woken up again a short time later. Each encoding takes about 40 minutes, and the remote PC sleeps after 1 hour. So, if the machine is currently on, I need a command to keep it alive inserted between each encode.

Here is my current script. It may seem a little weird, but it does what I need. I've trimmed out most of the encoding steps.


set avidemux="D:Programs\avidemux_2.5.6-1_win64\avidemux2_cli.exe"
set videocodec=
set audiocodec=
set curr_dir="D:\New Video"
set destination="D:\Encoded Temp\%%f.avi"

set therenamer="C:\Program Files (x86)\theRenamer\theRenamer.exe"
set renamer_source="D:\Encoded Temp"
set renamer_dest="D:\New TV Episodes"

set copy_dest="D:\Videos"
set move_dest="\\DOWNSTAIRS\Video"

chdir video1
set targetsize=300
for %%f in (*.mp4) do %avidemux% --video-codec %videocodec% --audio-codec %audiocodec% --video-conf 2pass=%targetsize% --force-alt-h264 --load "%%f" --save %destination% --quit
chdir /D %curr_dir%

chdir video2
set targetsize=375
for %%f in (*.mp4) do %avidemux% --video-codec %videocodec% --audio-codec %audiocodec% --video-conf 2pass=%targetsize% --force-alt-h264 --load "%%f" --save %destination% --quit

chdir %renamer_source%
del *.stat

%therenamer% -fetch -ff=%renamer_source% -af=%renamer_dest%

robocopy %renamer_dest% %copy_dest% /S /xa:h
robocopy %renamer_dest% %move_dest% /MOVE /S /xa:h
[/CODE]

Link to comment
https://www.neowin.net/forum/topic/1113959-windows-wakonlan-batch-script/
Share on other sites

8 answers to this question

Recommended Posts

  • 0

I'm not sure what the wol syntax is, but using the utility I mentioned already, you could simply insert the line

WakeMeOnLan.exe /wakeup x.x.x.x[/CODE]

(assuming x.x.x.x is the target's IP address) before you start your copy. I believe that the other checking to see if the machine is currently on, as you stated in your first post, is irrelevant.

  • 0

Anyone know if WoL or ping will keep the target machine awake?

What I'd like it to do is check if the machine is currently awake. If it is, then between each encode, do something to keep it awake and do the copy task at the end. If it isn't, then wait until the end of the script and prompt [y/n] whether or not it should wake the machine and copy the files.

  • 0

Some of the videos I'm encoding are downloaded, and sometimes they download really slow. So sometimes I want to run the script to encoded a few to get a head start, but I don't want to wake the machine and copy until I have all of them encoded.

  • 0

OK. Here's what i have so far. I haven't had a chance to test it. Anyone see any problems with it?


@echo off

set avidemux="D:Programs\avidemux_2.5.6-1_win64\avidemux2_cli.exe"
set videocodec=
set audiocodec=
set curr_dir="D:\New Video"
set destination="D:\Encoded Temp\%%f.avi"

set therenamer="C:\Program Files (x86)\theRenamer\theRenamer.exe"
set renamer_source="D:\Encoded Temp"
set renamer_dest="D:\Temp"
set copy_dest="D:\Video"
set move_dest="\\DOWNSTAIRS\Video"

set wol="D:\Programs\wol.exe"
set machine=Downstairs
set mac=0F0FEAFFFFF

echo.
ping -n 5 %machine%
if errorlevel 1 (
set awake=0
goto encode
)

echo.
echo %machine% is already awake.
set "awake=1"
goto encode

:encode
chdir /D %curr_dir%

chdir Video1
set targetsize=300
for %%f in (*.mp4) do %avidemux% --video-codec %videocodec% --audio-codec %audiocodec% --video-conf 2pass=%targetsize% --force-alt-h264 --load "%%f" --save %destination% --quit
chdir /D %curr_dir%

if awake=1 (
echo Sending WOL packet to %machine% (%mac%)
%wol% %mac%
)

chdir Video2
set targetsize=350
for %%f in (*.mp4) do %avidemux% --video-codec %videocodec% --audio-codec %audiocodec% --video-conf 2pass=%targetsize% --force-alt-h264 --load "%%f" --save %destination% --quit
chdir /D %curr_dir%
if awake=1 (
echo Sending WOL packet to %machine% (%mac%)
%wol% %mac%
)

chdir Video3
set targetsize=400
for %%f in (*.mp4) do %avidemux% --video-codec %videocodec% --audio-codec %audiocodec% --video-conf 2pass=%targetsize% --force-alt-h264 --load "%%f" --save %destination% --quit
chdir /D %curr_dir%

chdir %renamer_source%
del *.stat

if awake=1 (
goto renamer
)

:wake-on-lan
echo.
echo Sending WOL packet to %machine% (%mac%)
%wol% %mac%
wait 20
goto %renamer%

:renamer
%therenamer% -fetch -ff=%renamer_source% -af=%renamer_dest%
robocopy %renamer_dest% %copy_dest% /S /xa:h
robocopy %renamer_dest% %move_dest% /MOVE /S /xa:h
[/CODE]

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Download Apple macOS 26 Tahoe, iOS 26 official stock wallpapers in high quality by Aditya Tiwari Apple's latest software design can be thought of as the tech version of 'new year, new me.' macOS 26 is one among them, featuring the "Liquid Glass" as a translucent new material that reflects and refracts its surroundings. The updated macOS design is all over the place, including the Dock, sidebars, and toolbars, which have been refined to focus more on the user's content. Apple continued its annual tradition and introduced new wallpapers custom-made for macOS 26 Tahoe to go along with the new design language. These macOS Tahoe 26 wallpapers are available in light and dark theme options, complementing the transparent menu bar, which makes the display feel bigger. To download the wallpapers to your device, click on the image to open it, then right-click on the wallpaper and select "Save Image As." Apple said during the announcement that "the new design also unlocks more personalization on the Mac. App icons come to life in light or dark appearances, colorful new light and dark tints, as well as an elegant new clear look." Apple's Liquid Design-inspired default wallpapers are also available for iOS 26 in light and dark options. The company has utilised Liquid Design extensively when upgrading the wallpaper experience on iPhones. Lock Screen wallpapers on iPhone create a 3D effect when the device is moved around, giving the illusion that the objects in the image are popping out of the screen. The time displayed on the lock screen fluidly adapts to the available space in an image for a more dynamic feel. Not just the design, Apple has further bridged the gap between iPhone and Mac by adding new Continuity features to macOS 26 on these supported Mac models. This includes the new Phone app that lets you relay phone calls from your iPhone nearby. Just like widgets, macOS 26 can populate Live Activities from a nearby iPhone, enabling you to track your Uber ride, live sports scores, or incoming dinner orders. Source: Apple via 9to5Mac [1,2]
    • Whatever, you aimless bunch at M$ want to keep on wasting time and resources into applying makeup into that pig - I'll keep Open-Shell or Startallback thank you for nothing and be gone.
    • Maybe, I can’t quite recall. I skipped 8. My recollection is only it went from full screen to the option to not be full screen? It’s hazy lol
    • 8 to 8.1 was a pretty big overhaul, wasn’t it? 8.1 wasn’t really a new version of Windows. Is that what you were referring to in the tinkering comment?
  • Recent Achievements

    • Explorer
      MusicLover2112 went up a rank
      Explorer
    • Dedicated
      MadMung0 earned a badge
      Dedicated
    • Rookie
      CHUNWEI went up a rank
      Rookie
    • Enthusiast
      the420kid went up a rank
      Enthusiast
    • Conversation Starter
      NeoToad777 earned a badge
      Conversation Starter
  • Popular Contributors

    1. 1
      +primortal
      504
    2. 2
      ATLien_0
      268
    3. 3
      +FloatingFatMan
      254
    4. 4
      +Edouard
      202
    5. 5
      snowy owl
      169
  • Tell a friend

    Love Neowin? Tell a friend!