[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Windows: Scheduled Ruby script won't run

bdezonia

11/7/2007 6:31:00 PM

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.

11 Answers

Mohit Sindhwani

11/7/2007 6:48:00 PM

0

bdezonia@wisc.edu wrote:
> 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.




Mohit Sindhwani

11/7/2007 7:27:00 PM

0

Mohit Sindhwani wrote:
> 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.



bdezonia

11/7/2007 10:42:00 PM

0

On Nov 7, 1:27 pm, Mohit Sindhwani <mo_m...@onghu.com> wrote:
> Mohit Sindhwani wrote:
> > 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.

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?

Mohit Sindhwani

11/8/2007 7:28:00 AM

0

bdezonia@wisc.edu wrote:
>
> 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.



Mohit Sindhwani

11/8/2007 3:48:00 PM

0

Michael Gaunnac wrote:
> On Nov 7, 2007 1:35 PM, <bdezonia@wisc.edu> wrote:
>
>
> 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.



Mohit Sindhwani

11/8/2007 4:38:00 PM

0

Michael Gaunnac wrote:
> On Nov 7, 2007 1:35 PM, <bdezonia@wisc.edu> wrote:
>
>
> 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.



bdezonia

11/8/2007 6:27:00 PM

0

On Nov 8, 10:37 am, Mohit Sindhwani <mo_m...@onghu.com> wrote:
> Michael Gaunnac wrote:
> > On Nov 7, 2007 1:35 PM, <bdezo...@wisc.edu> wrote:
>
> > 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.

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.

Mohit Sindhwani

11/8/2007 6:56:00 PM

0

bdezonia@wisc.edu wrote:
> 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.






bdezonia

11/8/2007 7:40:00 PM

0

On Nov 8, 12:55 pm, Mohit Sindhwani <mo_m...@onghu.com> wrote:
> bdezo...@wisc.edu wrote:
> > 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!!!

rlkeller

11/8/2007 9:14:00 PM

0

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

bdezonia@wisc.edu wrote:
> On Nov 8, 12:55 pm, Mohit Sindhwani <mo_m...@onghu.com> wrote:
>
>> bdezo...@wisc.edu wrote:
>>
>>> 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!!!
>
>
>
>

--

Robert Keller
--------------------------------------------------
robert.keller@yahoo.com