Windows: Scheduled Ruby script won't run

B

bdezonia

Hello all,

I have looked on the web for an answer to my issue with little success
so I am trying here. I have a ruby script that I am scheduling at
computer startup on Windows. And apparently it never starts. If it
starts it should write a line to a file. From the command prompt the
script works fine but if logged in and attempting to start it from
Scheduled Tasks it fails too with no error messages or any evidence it
tried to start. I've checked account and password info for the task
and it is correct. In fact I've tried to different admin acounts
(though from a parent account). Is there something about the
environment maybe not being loaded since its not run from a shell that
is the problem? Any other ideas? Thanks for your insight.
 
M

Mohit Sindhwani

Hello all,

I have looked on the web for an answer to my issue with little success
so I am trying here. I have a ruby script that I am scheduling at
computer startup on Windows. And apparently it never starts. If it
starts it should write a line to a file. From the command prompt the
script works fine but if logged in and attempting to start it from
Scheduled Tasks it fails too with no error messages or any evidence it
tried to start. I've checked account and password info for the task
and it is correct. In fact I've tried to different admin acounts
(though from a parent account). Is there something about the
environment maybe not being loaded since its not run from a shell that
is the problem? Any other ideas? Thanks for your insight.

The most common problem is the path. I usually bootstrap my Ruby script
using a .cmd file that sets the path to my Ruby interpreter and then
calls the interpreter with the name of the script. It's always worked
for me. Also, if for some reason, you don't trust the Windows
scheduler, you could use PyCron - it's a cron replacement on Windows
that works very well (specially recommended if you plan to schedule the
script more frequently than just system startup).

This is what I use in my scripts:

REM Set up the environment variables for the script
set PATH_TO_RUBY=d:\InstantRails\ruby\bin
set RUBY=%PATH_TO_RUBY%\ruby.exe

REM ** settings for accessing the remaining scripts **
set PATH_TO_SCRIPTS=X:\Projects\scripts

%RUBY% %PATH_TO_SCRIPTS%\my_script.rb

Hope this helps.

Cheers,
Mohit.
11/8/2007 | 2:47 AM.
 
M

Mohit Sindhwani

Mohit said:
The most common problem is the path. I usually bootstrap my Ruby
script using a .cmd file that sets the path to my Ruby interpreter and
then calls the interpreter with the name of the script. It's always
worked for me. Also, if for some reason, you don't trust the Windows
scheduler, you could use PyCron - it's a cron replacement on Windows
that works very well (specially recommended if you plan to schedule
the script more frequently than just system startup).
*snip*

the other problem could be related to 'require' - if you require a file
that is in your local directory and not in a system standard path, you
will run into problems. You'll need to change directory to the
directory where your scripts are before you do the require.

Hope this helps.

Cheers,
Mohit.
11/8/2007 | 3:27 AM.
 
B

bdezonia

*snip*

the other problem could be related to 'require' - if you require a file
that is in your local directory and not in a system standard path, you
will run into problems. You'll need to change directory to the
directory where your scripts are before you do the require.

Hope this helps.

Cheers,
Mohit.
11/8/2007 | 3:27 AM.

Awesome idea Mohit (thanks!) but it does not work for me. The .rb
script will launch via a .cmd file from a command prompt. Now when I
try to start a scheduled task it at least does something. It returns
an error code of one. My file that is written to by the first line of
the script every time it is launched does not show any record of the
program actually being launched. And I did not see either the .rb file
or the ruby.exe show up in task manager (or any .cmd file either). The
only require statement refers to 'net/smtp'. Any more ideas?
 
M

Mohit Sindhwani

Awesome idea Mohit (thanks!) but it does not work for me. The .rb
script will launch via a .cmd file from a command prompt. Now when I
try to start a scheduled task it at least does something. It returns
an error code of one. My file that is written to by the first line of
the script every time it is launched does not show any record of the
program actually being launched. And I did not see either the .rb file
or the ruby.exe show up in task manager (or any .cmd file either). The
only require statement refers to 'net/smtp'. Any more ideas?

Hmm, OK.. Can you show us what the .cmd file does - from your statement
above, it seems that the launcher will run the .cmd file. Things don't
work after that?

If that's the case, the problem is either in the .cmd file or the .rb
script. If you could show us your .cmd and/ or .rb, it may help.
Anyway, take a look to see if there's anything in your code that assumes
opening a file in a specific directory or something.

If you're using SMTP at startup, are you sure that the network is up?
It could be that it fails to connect to the network?

Anyway, it's difficult to double guess without seeing what you're trying
to do.

Cheers,
Mohit.
11/8/2007 | 3:15 PM.
 
M

Mohit Sindhwani

Michael said:
The attached file contains the parts of a Scheduled Task that reports
a restart of a Windows OS instance through email and any errors
associated with Terminal Services. The parts are separated by dashes.
This may be more than what you are looking for but it contains some
hard won information.


Hi, just starting to look through this. You call it with server name
starting with \\ right?


Cheers,
Mohit.
11/8/2007 | 11:45 PM.
 
M

Mohit Sindhwani

Michael said:
The attached file contains the parts of a Scheduled Task that reports
a restart of a Windows OS instance through email and any errors
associated with Terminal Services. The parts are separated by dashes.
This may be more than what you are looking for but it contains some
hard won information.
Hi, I'm not sure and I can't tell much from the script without trying it
out. Could you try something? In your .cmd file, can you do a chdir to
the directory in which it's supposed to run. Do the same for the Ruby
script also. See if that helps.

Cheers,
Mohit.
11/9/2007 | 12:37 AM.
 
B

bdezonia

Hi, I'm not sure and I can't tell much from the script without trying it
out. Could you try something? In your .cmd file, can you do a chdir to
the directory in which it's supposed to run. Do the same for the Ruby
script also. See if that helps.

Cheers,
Mohit.
11/9/2007 | 12:37 AM.

Okay, here is a test script/cmd combo that runs from the command line
but not from a Scheduled Task under Windows. It results in an error
code of one.

##### blunk.cmd file

c:
cd \scripts
c:\ruby\bin\ruby.exe c:\scripts\blunk.rb

# I have tried using the env variable idea earlier with no different
outcome

##### blunk.rb file

PATCHFILE = "c:/scripts/patchDayNotice" # also without absolute path
tried and failed

File.open(PATCHFILE,"a") do | file |
file.print("BLUNK called\n")
print "BLUNK called\n"
end

Any help anyone can give would be great. Is the error return code of
one from Ruby? What error is that? I can't find any info on that.
 
M

Mohit Sindhwani

Okay, here is a test script/cmd combo that runs from the command line
but not from a Scheduled Task under Windows. It results in an error
code of one.

##### blunk.cmd file

c:
cd \scripts
c:\ruby\bin\ruby.exe c:\scripts\blunk.rb

# I have tried using the env variable idea earlier with no different
outcome

##### blunk.rb file

PATCHFILE = "c:/scripts/patchDayNotice" # also without absolute path
tried and failed

File.open(PATCHFILE,"a") do | file |
file.print("BLUNK called\n")
print "BLUNK called\n"
end

Any help anyone can give would be great. Is the error return code of
one from Ruby? What error is that? I can't find any info on that.

OK! I just tried the cmd/ rb that you sent me. Yes, it works fine from
the command line. I also set it up as a 1-time task in Windows
scheduler [you'll understand why I didn't set it to be something that
runs only on bootup] and it just ran from Windows scheduler. It seems
to work fine for me. It appends to the file.

I did not set any advanced properties in Windows scheduler.

Now, I'm lost as to what may be causing the problem for you.

Cheers,
Mohit.
11/9/2007 | 2:55 AM.
 
B

bdezonia

Okay, here is a test script/cmd combo that runs from the command line
but not from a Scheduled Task under Windows. It results in an error
code of one.
##### blunk.cmd file
c:
cd \scripts
c:\ruby\bin\ruby.exe c:\scripts\blunk.rb
# I have tried using the env variable idea earlier with no different
outcome
##### blunk.rb file
PATCHFILE = "c:/scripts/patchDayNotice" # also without absolute path
tried and failed
File.open(PATCHFILE,"a") do | file |
file.print("BLUNK called\n")
print "BLUNK called\n"
end
Any help anyone can give would be great. Is the error return code of
one from Ruby? What error is that? I can't find any info on that.

OK! I just tried the cmd/ rb that you sent me. Yes, it works fine from
the command line. I also set it up as a 1-time task in Windows
scheduler [you'll understand why I didn't set it to be something that
runs only on bootup] and it just ran from Windows scheduler. It seems
to work fine for me. It appends to the file.

I did not set any advanced properties in Windows scheduler.

Now, I'm lost as to what may be causing the problem for you.

Cheers,
Mohit.
11/9/2007 | 2:55 AM.

I moved it to a different machine and it launched! Thanks Mohit!!!
 
R

Robert Keller

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

I ran into a similar problem a while back where my code ran fine if I
was logged into windows and using a command line, but the same code
would not run under a batch situation. Turned out to be the security
settings for the windows account did not allow batch running.

Robert

Okay, here is a test script/cmd combo that runs from the command line
but not from a Scheduled Task under Windows. It results in an error
code of one.

##### blunk.cmd file

c:
cd \scripts
c:\ruby\bin\ruby.exe c:\scripts\blunk.rb

# I have tried using the env variable idea earlier with no different
outcome

##### blunk.rb file

PATCHFILE = "c:/scripts/patchDayNotice" # also without absolute path
tried and failed

File.open(PATCHFILE,"a") do | file |
file.print("BLUNK called\n")
print "BLUNK called\n"
end

Any help anyone can give would be great. Is the error return code of
one from Ruby? What error is that? I can't find any info on that.
OK! I just tried the cmd/ rb that you sent me. Yes, it works fine from
the command line. I also set it up as a 1-time task in Windows
scheduler [you'll understand why I didn't set it to be something that
runs only on bootup] and it just ran from Windows scheduler. It seems
to work fine for me. It appends to the file.

I did not set any advanced properties in Windows scheduler.

Now, I'm lost as to what may be causing the problem for you.

Cheers,
Mohit.
11/9/2007 | 2:55 AM.

I moved it to a different machine and it launched! Thanks Mohit!!!
 
M

Mohit Sindhwani

I moved it to a different machine and it launched! Thanks Mohit!!!

Well, I did little more than confirming your worst fears that it wasn't
working for you! But, I"m glad that helped.

Cheers
Mohit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top