Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Windows: Scheduled Ruby script won't run

Reply
Thread Tools

Windows: Scheduled Ruby script won't run

 
 
bdezonia@wisc.edu
Guest
Posts: n/a
 
      11-07-2007
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.

 
Reply With Quote
 
 
 
 
Mohit Sindhwani
Guest
Posts: n/a
 
      11-07-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) 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.




 
Reply With Quote
 
 
 
 
Mohit Sindhwani
Guest
Posts: n/a
 
      11-07-2007
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.



 
Reply With Quote
 
bdezonia@wisc.edu
Guest
Posts: n/a
 
      11-07-2007
On Nov 7, 1:27 pm, Mohit Sindhwani <(E-Mail Removed)> 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?

 
Reply With Quote
 
Mohit Sindhwani
Guest
Posts: n/a
 
      11-08-2007
(E-Mail Removed) 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.



 
Reply With Quote
 
Mohit Sindhwani
Guest
Posts: n/a
 
      11-08-2007
Michael Gaunnac wrote:
> On Nov 7, 2007 1:35 PM, <(E-Mail Removed)> 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.



 
Reply With Quote
 
Mohit Sindhwani
Guest
Posts: n/a
 
      11-08-2007
Michael Gaunnac wrote:
> On Nov 7, 2007 1:35 PM, <(E-Mail Removed)> 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.



 
Reply With Quote
 
bdezonia@wisc.edu
Guest
Posts: n/a
 
      11-08-2007
On Nov 8, 10:37 am, Mohit Sindhwani <(E-Mail Removed)> wrote:
> Michael Gaunnac wrote:
> > On Nov 7, 2007 1:35 PM, <(E-Mail Removed)> 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.

 
Reply With Quote
 
Mohit Sindhwani
Guest
Posts: n/a
 
      11-08-2007
(E-Mail Removed) 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.






 
Reply With Quote
 
bdezonia@wisc.edu
Guest
Posts: n/a
 
      11-08-2007
On Nov 8, 12:55 pm, Mohit Sindhwani <(E-Mail Removed)> wrote:
> (E-Mail Removed) 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!!!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(How) Can you run another ruby script, from a ruby script? 3lionz Wexler Ruby 2 08-24-2010 04:27 AM
Run a scheduled backup David Gray Computer Support 0 03-29-2005 01:28 PM
Scheduled Task script wont run grounghog Microsoft Certification 0 08-12-2004 03:47 PM
Scheduled Task Won't Run Phyllis Computer Support 8 01-08-2004 01:29 AM
Re: Scheduled Veritas Exec Does Not Run? Greg Townsend NZ Computing 3 08-08-2003 02:39 AM



Advertisments