Sign in to follow this  
Followers 0
eRIZ

Script executed from Task Scheduler freezes

4 posts in this topic

Hi!

I've written simple script for getting newest backup created by DirectAdmin:

#include <Constants.au3>

Local $foo = Run("plink user@host ""ls -t /catalog/with/backups | head -n 1""", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $line
While 1
    $line &= StdoutRead($foo)
    If @error Then ExitLoop
Wend

$line = StringTrimRight($line, 1)
MsgBox(1, "title", $line)

$o = Run("E:\\bin\\pscp -C user@host:/catalog/with/backups/" &$line & " " &$line, "E:\\backups")

It works very well if executed normally (eg. double click on script). But something goes wrong if it's executed by Windows7 Task Scheduler. Nevetherless permissions - system or of my account; tried to use compiled version of scripts - no change.

I tried to find out what's coming on.

The process tree started by Task Scheduler freezes for some, unknown reason. It looks like this:

Posted Image

and they don't stop... Any ideas how resolve this problem?

Cheers,

eRIZ

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

IIRC the task scheduler runs the program with the permissions you specify. But the environment a user gets when he logs on by the login script is not available to the program started by the task scheduler.

Try to replace drive letters by UNC paths (\\Servername\share\path).

I'm not sure what it needs to let the task scheduler place something on the desktop (MsgBox etc.).

Do yourself a favour and put some error checking in your script. Check @error after the run and statements and write error messages to a log if @error <> 0.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

IIRC the task scheduler runs the program with the permissions you specify. But the environment a user gets when he logs on by the login script is not available to the program started by the task scheduler.

I wrote I tried on different permissions.

Try to replace drive letters by UNC paths (\\Servername\share\path).

Okay, but application is correctly executed, what does the path matter here?

I'm not sure what it needs to let the task scheduler place something on the desktop (MsgBox etc.).

Oh, I forgot - I added MsgBox for debug purposes.

Do yourself a favour and put some error checking in your script. Check @error after the run and statements and write error messages to a log if @error <> 0.

How can I pass through the error checking if the code after Wend isn't executed?

Share this post


Link to post
Share on other sites

Okay, another try.

Let's say you interactively logon to user xyz. The logon script assigns UNC path \\server\share\path as drive D:\ If user xyz has the needed permissions he can access files residing on this drive.

If the task scheduler runs a task with the permission of user xyz there is no D:\ drive, just the permissions to access files on \\server\share\path.

So you can either access a file using UNC notation or assign the UNC path to a drive yourself in your script.

Okay, but application is correctly executed

That's something you didn't mention in your first post.

Error checking means: Check if an action you started finished without errors. You start a program and then wait for some output of this program. If the start of the program wasn't successful you will wait forever, right?

So please insert line

If @error <> 0 then FileWriteLine("C:\temp\log.txt", "run of ... ended with @error " & @error)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0