none
Task Scheduler will not run .cmd file that run a perlscript

    Question

  • I have a scrip will call a perlscript. The .cmd file runs properly when I click it manually. I set the Task Scheduler to run every 5 minutes, but it didn't work.

    Here is the .cmd file

    ********************************************
    @echo off
    net use k: \\myserver1\myfolder\
    k:
    c:\perl\bin\perl.exe myperl.pl
    net use /delete /y k:
    ********************************************

    Any help is appreciated.


    • Edited by funnycode Thursday, June 07, 2012 1:02 AM typo
    Thursday, June 07, 2012 12:57 AM

Answers

  • If you add some logging to your code then you will soon find out what's wrong:

    @echo off
    if not exist c:\Logs md c:\Logs
    set Logfile=c:\Logs\Per.log
    echo %UserName% %date% %time%T >> %LogFile%
    net use k: \\myserver1\myfolder\  1>> %LogFile%  2>>&1
    k:  1>> %LogFile%  2>>&1
    c:\perl\bin\perl.exe myperl.pl  1>> %LogFile%  2>>&1
    net use /delete /y k:  1>> %LogFile%  2>>&1
    echo. 1>> %LogFile%  2>>&1

    Friday, June 08, 2012 6:36 AM

All replies

  • I think you need to post in a Perl forum....

    ¯\_(ツ)_/¯

    Thursday, June 07, 2012 1:17 AM
  • Hi,

    First of all, when you say that something didn't work, you have to say how it didn't work.

    Secondly, I generally don't recommend mapping drives and connecting to network resources using a drive letter from an automated task. This can be problematic when dealing within the security restrictions of a scheduled task.

    Bill

    Thursday, June 07, 2012 2:19 AM
  • I want the script to be run as "Run whether user is logged on or not". So I used UNC instead of drive letter.

    The script (the .cmd file) runs fine if I manually click on it. However, when I set the scheduler to run it every five minutes, the Task Scheduler history panel would tell me it ran "successfully" without error code.

    I am not sure how to debug the Task Scheduler.

    Thank you, Bill, for your help.

    Thursday, June 07, 2012 10:50 PM
  • Thanks.

    The Perl script runs fine. The batch file runs fine alone, but it just won't run by Task Scheduler.

    ;-(

    Thursday, June 07, 2012 10:52 PM
  • Thanks.

    The Perl script runs fine. The batch file runs fine alone, but it just won't run by Task Scheduler.

    ;-(

    You have not yet told us what it is that is not working. How do you know that the file is not working when you run it under the task scheduler?  What is the error message?   What happens?  What doesn't happen?

    Since this is Perl why aren't yuo posting in the Perl forum?  This is a Wndows administrative scripting forum for Microsoft scripting technologies.  Perl is not a Microsoft product.

    You have failed to explain which OS you are running.  You have failed to mention how the task is  configured.   No one in any forum can likely help you as long as you are so vague about what it is you are doing.  Try to think about this as if someone was asking you these questions and you could not see them or their system and you have no idea what it is they are trying to do.


    ¯\_(ツ)_/¯

    Friday, June 08, 2012 12:35 AM
  • Hi funnycode,

    Like I said: If you say that something didn't work, you have to say how it didn't work. jrv explained this a little more. What do you mean it didn't work? How do you know? What is or isn't happening? You have not posted any of your code, and we cannot see your screen.

    As a troubleshooting step, you remove perl from the equation entirely and just run a one-line batch file such as:

    echo Hello, world > \\server\share\test.txt

    ...to test what you're trying to do. Nothing to do with perl - just create a text file in the specified location. This can aid in troubleshooting.

    You also haven't given any details about how you have configured the scheduled task. As jrv said: "Try to think about this as if someone was asking you these questions and you could not see them or their system and you have no idea what it is they are trying to do."

    Bill

    Friday, June 08, 2012 4:13 AM
  • If you add some logging to your code then you will soon find out what's wrong:

    @echo off
    if not exist c:\Logs md c:\Logs
    set Logfile=c:\Logs\Per.log
    echo %UserName% %date% %time%T >> %LogFile%
    net use k: \\myserver1\myfolder\  1>> %LogFile%  2>>&1
    k:  1>> %LogFile%  2>>&1
    c:\perl\bin\perl.exe myperl.pl  1>> %LogFile%  2>>&1
    net use /delete /y k:  1>> %LogFile%  2>>&1
    echo. 1>> %LogFile%  2>>&1

    Friday, June 08, 2012 6:36 AM
  • As there has been no activity in this thread for a few days, we assume the issue is resolved. We will mark it as "answered" to assist others in similar situations. If you disagree, please reply with further information. You can unmark the answer if you wish. If a reply helped answer your question, please mark it as the answer.


    Richard Mueller - MVP Directory Services

    Friday, June 15, 2012 12:13 AM