locked
Batch file and Scheduled Tasks RRS feed

  • Question

  • Good afternoon,

    Apologies if this is in the wrong forum but I struggled to find a more appropriate category for my query.

    I've got a batch file on a Windows 2003 server that simply telnets to an address over port 80 in order to open a VPN tunnel (we've had trouble with the VPN, so this scheduled task runs every hour to send traffic and keep the tunnel open).

    If I open 'Scheduled Tasks' and run the task manually it works as I'd expect (task runs, and then is closed after duration timer is reached). However, when it's scheduled to run it doesn't seem to even run the batch file (even though it shows the 'Last Run Time' as though it's gone OK).

    Below is taken from the Scheduled Tasks log.

    --- Run the task manually. Traffic successfully sent ---

    "JOB.job" (BATCH.bat)
        Started 15/01/2014 11:37:30
    "JOB.job" (BATCH.bat) 15/01/2014 11:38:30 ** WARNING **
        The task was forced to close since its execution time exceeded the configured maximum.
        You may want to go to the Settings page and increase the "Stop the scheduled task after" time.

    --- Task run automatically. No traffic sent ---

    "JOB.job" (BATCH.bat)
        Started 15/01/2014 11:00:01
    "JOB.job" (BATCH.bat)
        Finished 15/01/2014 11:00:01
        Result: The task completed with an exit code of (57).

    I've tried to find any reference to 'exit code of (57)' but I've not found anything yet.

    Any help would be much appreciated.

    Thanks

    Wednesday, January 15, 2014 12:17 PM

Answers

  • The part you are ignoring is that you are trying to automate a process that was never intended to be automated. I suggest acquiring a Telnet client that is designed to be scripted so you have more control of what happens when there is an error.

    Why must you use Telnet to keep a VPN up when the VPN software is designed to do that automatically. Just set the client to auto-connect on a lost connection.

    Any network errors will likely hang your telnet session. The error is only one of many. It is throwing your batch out of sync with whatever process you think you need to do. Since there is no automation support you cannot detect the issue.

    If you were to use PowerShell you might be able to detect the errors but you would still be fighting an uphill battle.


    ¯\_(ツ)_/¯

    • Marked as answer by Bill_Stewart Monday, February 24, 2014 7:17 PM
    Wednesday, January 15, 2014 1:24 PM

All replies

  • Have you set the task to run as System or as a real user?
    Wednesday, January 15, 2014 12:23 PM
  • It's set to run as a user at the moment. Curiously it did seem to work automatically (with exactly the same configuration as now) for the first 48 hours or so after it was created - only to stop working and start producing the 'exit code (57)' message for the last few days.
    Wednesday, January 15, 2014 12:30 PM
  • This is not really a scripting issue.  You will do better if you post in a more appropriate forum.

    The errors are pretty clear.  The batch is being cancelled because its run time limit was exceeded.  It is likely that the remote is terminating the connection and leaving telnet hung.

    This kind of Rube Goldberg arrangement is not a very reliable or secure solution.  Consider configuring your VPN correctly.  Set it to auto-redial on connection lost.


    ¯\_(ツ)_/¯

    Wednesday, January 15, 2014 12:48 PM

  • C:\>net helpmsg 57
    
    A network adapter hardware error occurred.
    

    Not a scripting question.

    Bill

    Wednesday, January 15, 2014 1:10 PM
  • The instance with the batch time limit warning is the job working as configured. The batch itself takes a second to run so having a 60 second timeout on the scheduled task shouldn't ever cause an issue. We're using the timeout as a way to close the task off more than anything.

    It's the difference between running this manually from Scheduled Tasks (works fine) and waiting for the automatic scheduled runs (not working) that I'm not understanding. Please correct me if I'm wrong, but surely if it works as expected when I run manually, I can expect it to run the same successful job at the defined schedule times?

    Wednesday, January 15, 2014 1:14 PM
  • The part you are ignoring is that you are trying to automate a process that was never intended to be automated. I suggest acquiring a Telnet client that is designed to be scripted so you have more control of what happens when there is an error.

    Why must you use Telnet to keep a VPN up when the VPN software is designed to do that automatically. Just set the client to auto-connect on a lost connection.

    Any network errors will likely hang your telnet session. The error is only one of many. It is throwing your batch out of sync with whatever process you think you need to do. Since there is no automation support you cannot detect the issue.

    If you were to use PowerShell you might be able to detect the errors but you would still be fighting an uphill battle.


    ¯\_(ツ)_/¯

    • Marked as answer by Bill_Stewart Monday, February 24, 2014 7:17 PM
    Wednesday, January 15, 2014 1:24 PM