# Ruby and cron help

**URL:** <https://rubytalk.org/t/ruby-and-cron-help/5274>\
**Category:** ruby-talk\
**Created:** [21 March 2003 19:44 UTC](https://rubytalk.org/t/ruby-and-cron-help/5274 "2003-03-21T19:44:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Probert5](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@Mark\_Probert5](https://rubytalk.org/u/Mark_Probert5)\
**Post date:** [21 March 2003 19:44 UTC](https://rubytalk.org/t/ruby-and-cron-help/5274/1 "2003-03-21T19:44:40Z")

</div>

Hi, rubyists.

I think this is more a cron rather than a ruby problem.  
However, I am stumped.

I am running ruby 1.6.8 under Solaris 6.

wcary3zg:~/src/ruby/utils% crontab -l  
0,15,30,45 \* \* \* \* /opt/home/mark/bin/blah

wcary3zg:~/src/ruby/utils% cat ~/bin/blah  
#! /usr/local/bin/zsh  
cd ~/src/ruby/utils  
/usr/local/bin/ruby timestamp.rb \> ~/tmp/timestamp.out  
/usr/local/bin/ruby blah.rb \> ~/tmp/blah.out

timestamp.rb contains “puts Time.now” just to show that  
ruby is working ok. blah.rb is the application I am  
really interested in. Running “blah” from the command  
line works fine. It fails to work from cron, though  
the command is executed (from /var/cron/log) and the  
timestamp.out file is updated.

Any ideas?

> **···**
>
> –  
> -mark.
> 
> * * *
> 
> ## Mark Probert probertm@NOSPAM\_nortelnetworks.com Nortel Networks ph. (613) 768-1082
> 
> All opinions expressed are my own and do not  
> reflect in any way those of Nortel Networks.

---

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Joel\_VanderWerf1](https://rubytalk.org/u/Joel_VanderWerf1)\
**Post date:** [21 March 2003 20:01 UTC](https://rubytalk.org/t/ruby-and-cron-help/5274/2 "2003-03-21T20:01:39Z")

</div>

Mark Probert wrote:

> Hi, rubyists.
> 
> I think this is more a cron rather than a ruby problem.  
> However, I am stumped.
> 
> I am running ruby 1.6.8 under Solaris 6.
> 
> wcary3zg:~/src/ruby/utils% crontab -l  
> 0,15,30,45 \* \* \* \* /opt/home/mark/bin/blah
> 
> wcary3zg:~/src/ruby/utils% cat ~/bin/blah  
> #! /usr/local/bin/zsh  
> cd ~/src/ruby/utils  
> /usr/local/bin/ruby timestamp.rb \> ~/tmp/timestamp.out  
> /usr/local/bin/ruby blah.rb \> ~/tmp/blah.out
> 
> timestamp.rb contains “puts Time.now” just to show that  
> ruby is working ok. blah.rb is the application I am  
> really interested in. Running “blah” from the command  
> line works fine. It fails to work from cron, though  
> the command is executed (from /var/cron/log) and the  
> timestamp.out file is updated.
> 
> Any ideas?

Does blah run if you comment out the timestamp line?

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard1](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Ara.T.Howard1](https://rubytalk.org/u/Ara.T.Howard1)\
**Post date:** [21 March 2003 20:04 UTC](https://rubytalk.org/t/ruby-and-cron-help/5274/3 "2003-03-21T20:04:52Z")

</div>

what happens if you replace

timestamp.rb

and

blah.rb

with their absolute paths?

you could try changing

> /usr/local/bin/ruby blah.rb \> ~/tmp/blah.out

to

> /usr/local/bin/ruby blah.rb

and see what cron mails you.

-a

> **···**
>
> On Fri, 21 Mar 2003, Mark Probert wrote:
> 
> > Hi, rubyists.
> > 
> > I think this is more a cron rather than a ruby problem.  
> > However, I am stumped.
> > 
> > I am running ruby 1.6.8 under Solaris 6.
> > 
> > wcary3zg:~/src/ruby/utils% crontab -l  
> > 0,15,30,45 \* \* \* \* /opt/home/mark/bin/blah
> > 
> > wcary3zg:~/src/ruby/utils% cat ~/bin/blah  
> > #! /usr/local/bin/zsh  
> > cd ~/src/ruby/utils  
> > /usr/local/bin/ruby timestamp.rb \> ~/tmp/timestamp.out  
> > /usr/local/bin/ruby blah.rb \> ~/tmp/blah.out
> > 
> > timestamp.rb contains “puts Time.now” just to show that  
> > ruby is working ok. blah.rb is the application I am  
> > really interested in. Running “blah” from the command  
> > line works fine. It fails to work from cron, though  
> > the command is executed (from /var/cron/log) and the  
> > timestamp.out file is updated.
> > 
> > Any ideas?
> > 
> > –  
> > -mark.
> > 
> > * * *
> > 
> > ## Mark Probert probertm@NOSPAM\_nortelnetworks.com Nortel Networks ph. (613) 768-1082
> > 
> > All opinions expressed are my own and do not  
> > reflect in any way those of Nortel Networks.
> 
> # –
> 
> > Ara Howard  
> > NOAA Forecast Systems Laboratory  
> > Information and Technology Services  
> > Data Systems Group  
> > R/FST 325 Broadway  
> > Boulder, CO 80305-3328  
> > Email: [ahoward@fsl.noaa.gov](mailto:ahoward@fsl.noaa.gov)  
> > Phone: 303-497-7238  
> > Fax: 303-497-7259  
> > ====================================

---

<div class="post-metadata">

**Author:** ![Thien\_Vuong1](https://avatars.discourse-cdn.com/v4/letter/t/c57346/32.png) [@Thien\_Vuong1](https://rubytalk.org/u/Thien_Vuong1)\
**Post date:** [31 March 2003 03:12 UTC](https://rubytalk.org/t/ruby-and-cron-help/5274/4 "2003-03-31T03:12:31Z")

</div>

Mark Probert wrote:

> Hi, rubyists.
> 
> I think this is more a cron rather than a ruby problem.  
> However, I am stumped.
> 
> I am running ruby 1.6.8 under Solaris 6.
> 
> wcary3zg:~/src/ruby/utils% crontab -l  
> 0,15,30,45 \* \* \* \* /opt/home/mark/bin/blah
> 
> wcary3zg:~/src/ruby/utils% cat ~/bin/blah  
> #! /usr/local/bin/zsh  
> cd ~/src/ruby/utils  
> /usr/local/bin/ruby timestamp.rb \> ~/tmp/timestamp.out  
> /usr/local/bin/ruby blah.rb \> ~/tmp/blah.out
> 
> timestamp.rb contains “puts Time.now” just to show that  
> ruby is working ok. blah.rb is the application I am  
> really interested in. Running “blah” from the command  
> line works fine. It fails to work from cron, though  
> the command is executed (from /var/cron/log) and the  
> timestamp.out file is updated.
> 
> Any ideas?

Just to make sure all the output from the command are captured,  
you may want to do this.

cd ~/src/ruby/utils  
/usr/local/bin/ruby timestamp.rb \> ~/tmp/timestamp.out 2\>&1  
/usr/local/bin/ruby blah.rb \> ~/tmp/blah.out 2\>&1

and check the output

Also, if your login shell is not of the csh variety, try testing  
it with

rsh localhost /opt/home/mark/bin/blah

This emulates pretty well the cron execution environment. cron  
run a program with almost none of your environment, so you need to  
setup most environment variables that is normally in .profile/.cshrc

---

<div class="post-metadata">

**Author:** ![Berger\_Daniel2](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@Berger\_Daniel2](https://rubytalk.org/u/Berger_Daniel2)\
**Post date:** [21 March 2003 20:22 UTC](https://rubytalk.org/t/ruby-and-cron-help/5274/5 "2003-03-21T20:22:03Z")

</div>

Joel VanderWerf wrote:

> Mark Probert wrote:  
> Hi, rubyists.
> 
> I think this is more a cron rather than a ruby problem.  
> However, I am stumped.
> 
> I am running ruby 1.6.8 under Solaris 6.
> 
> wcary3zg:~/src/ruby/utils% crontab -l  
> 0,15,30,45 \* \* \* \* /opt/home/mark/bin/blah

0,15,30,45 \* \* \* \* /opt/home/mark/bin/blah 2\>~/tmp/blah.err

See what shows up in blah.err.

Also, with DBI/Oracle I’ve noticed that I explictly have to set some  
environment variables for cron by including “/usr/bin/env VAR=val”, etc.

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![Mark\_Probert5](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@Mark\_Probert5](https://rubytalk.org/u/Mark_Probert5)\
**Post date:** [21 March 2003 20:45 UTC](https://rubytalk.org/t/ruby-and-cron-help/5274/6 "2003-03-21T20:45:23Z")

</div>

Joel VanderWerf [vjoel@PATH.Berkeley.EDU](mailto:vjoel@PATH.Berkeley.EDU) did say …

> Does blah run if you comment out the timestamp line?

No, unfortunately. The idea of the timestamp line was  
to see if it was a problem running ruby, or cron, or  
the driver. They all seem to be ok.

The output of /var/cron/log is

> CMD: /opt/home/mark/bin/blah  
> mark 761 c Fri Mar 21 15:00:00 2003  
> \< mark 761 c Fri Mar 21 15:00:00 2003 rc=1

The script will runtime is around 10 mins (there  
are 2 x 5 minute intentional sleeps).

Is there anyway of working out what cron is doing or  
capturing the output? I have tried

0,15,30,45 \* \* \* \* /opt/home/mark/bin/vtx1 \> ~/tmp/cron.out 2\>&1

though the cron.out file is empty …

Thanks for your help,

> **···**
>
> –  
> -mark.
> 
> * * *
> 
> ## Mark Probert probertm@NOSPAM\_nortelnetworks.com Nortel Networks ph. (613) 768-1082
> 
> All opinions expressed are my own and do not  
> reflect in any way those of Nortel Networks.

---

<div class="post-metadata">

**Author:** ![Mark\_Probert5](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@Mark\_Probert5](https://rubytalk.org/u/Mark_Probert5)\
**Post date:** [21 March 2003 20:45 UTC](https://rubytalk.org/t/ruby-and-cron-help/5274/7 "2003-03-21T20:45:27Z")

</div>

ahoward [ahoward@fsl.noaa.gov](mailto:ahoward@fsl.noaa.gov) did say …

> what happens if you replace
> 
> timestamp.rb
> 
> and
> 
> blah.rb
> 
> with their absolute paths?

Same effect

> you could try changing
> 
> > /usr/local/bin/ruby blah.rb \> ~/tmp/blah.out
> 
> to
> 
> > /usr/local/bin/ruby blah.rb
> 
> and see what cron mails you.

-smile-

Nothing …

Thanks for your help!

> **···**
>
> > On Fri, 21 Mar 2003, Mark Probert wrote:
> 
> –  
> -mark.
> 
> * * *
> 
> ## Mark Probert probertm@NOSPAM\_nortelnetworks.com Nortel Networks ph. (613) 768-1082
> 
> All opinions expressed are my own and do not  
> reflect in any way those of Nortel Networks.

---

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Joel\_VanderWerf1](https://rubytalk.org/u/Joel_VanderWerf1)\
**Post date:** [21 March 2003 20:55 UTC](https://rubytalk.org/t/ruby-and-cron-help/5274/8 "2003-03-21T20:55:03Z")

</div>

Mark Probert wrote:

> 0,15,30,45 \* \* \* \* /opt/home/mark/bin/vtx1 \> ~/tmp/cron.out 2\>&1

I’ve had trouble using ~ in crontab, so I use $HOME, which seems to  
work. (Solaris 7, anyway.)

---

<div class="post-metadata">

**Author:** ![Jos\_Backus1](https://avatars.discourse-cdn.com/v4/letter/j/7feea3/32.png) [@Jos\_Backus1](https://rubytalk.org/u/Jos_Backus1)\
**Post date:** [22 March 2003 07:09 UTC](https://rubytalk.org/t/ruby-and-cron-help/5274/9 "2003-03-22T07:09:17Z")

</div>

Yeah, Solaris’ /bin/sh doesn’t even grok ~.

Have you tried truss’ing cron and its children right before the job is  
supposed to run? Something like:

```
$ truss -o /tmp/cron.trace -vall -f -p <cron pid>

```

Then check /tmp/cron.trace after the job has ran. I know, it’s a sledgehammer  
approach…

> **···**
>
> On Sat, Mar 22, 2003 at 05:55:03AM +0900, Joel VanderWerf wrote:
> 
> > Mark Probert wrote:
> > 
> > > 0,15,30,45 \* \* \* \* /opt/home/mark/bin/vtx1 \> ~/tmp/cron.out 2\>&1
> > 
> > I’ve had trouble using ~ in crontab, so I use $HOME, which seems to  
> > work. (Solaris 7, anyway.)
> 
> –  
> Jos Backus _/ //_/ Sunnyvale, CA  
> \_/ \_/ \_/  
> _/ //_/  
> \_/ \_/ \_/ _/  
> jos at [catnook.com](http://catnook.com)// //_/ require ‘std/disclaimer’
