# Running ab command in cron

**URL:** <https://www.ruby-forum.com/t/running-ab-command-in-cron/144335>\
**Category:** Ruby\
**Created:** [July 28, 2008, 7:06pm UTC](https://www.ruby-forum.com/t/running-ab-command-in-cron/144335 "2008-07-28T19:06:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![voodoox33](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@voodoox33](https://www.ruby-forum.com/u/voodoox33)\
**Post date:** [July 28, 2008, 7:06pm UTC](https://www.ruby-forum.com/t/running-ab-command-in-cron/144335/1 "2008-07-28T19:06:38Z")

</div>

def get\_web\_performance(instance\_url)  
web\_performance = -111

ab\_command = “ab -n 1000 -c 5 -d -S -k http://” + instance\_url +  
"/dbcon/index.php:80/ "  
puts ab\_command  
result = IO.popen(ab\_command)  
puts result  
pipe = result.readlines  
pipe.each do |line|  
puts line  
if line =~ /^apr\_socket\_recv/  
#puts 111  
break  
end  
if line =~ /^Time per request:/  
#puts line  
stats = line.split  
#puts stats[3]  
web\_performance = stats[3].to\_i  
puts web\_performance  
break  
end  
#puts line  
end  
return web\_performance  
end  
if i run this code in shell. it works fine. when i run the ruby script  
with cron i dont get any output of this line IO.popen(ab\_command). is  
there any thing i am missing?

---

<div class="post-metadata">

**Author:** ![voodoox33](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@voodoox33](https://www.ruby-forum.com/u/voodoox33)\
**Post date:** [July 28, 2008, 8:01pm UTC](https://www.ruby-forum.com/t/running-ab-command-in-cron/144335/2 "2008-07-28T20:01:49Z")

</div>

On Jul 28, 2008, at 11:06 AM, Zakir Zakir wrote:

> ## if i run this code in shell. it works fine. when i run the ruby script with cron i dont get any output of this line IO.popen(ab\_command). is there any thing i am missing?

maybe the full path to ab - cron does not have your environment.

a @ [http://codeforpeople.com/](http://codeforpeople.com/)

---

<div class="post-metadata">

**Author:** ![voodoox33](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@voodoox33](https://www.ruby-forum.com/u/voodoox33)\
**Post date:** [July 29, 2008, 5:35am UTC](https://www.ruby-forum.com/t/running-ab-command-in-cron/144335/3 "2008-07-29T05:35:33Z")

</div>

> maybe the full path to ab - cron does not have your environment.

yap worked like charm. thankx
