title: firefox not opening - cron, ruby, firewatir
body: <p>I have written a ruby script which opens up dlink admin page in firefox and does a ADSL connection or disconnection.</p>
  
  <p>I could run this script in the terminal without any problem. But if I put it as cron job, it doesn't fire up firefox.</p>
  
  <p>This is the entry I have in <em>crontab</em></p>
  
  <pre><code># connect to dataone
  55 17 * * * ruby /home/raguanu/Dropbox/nettie.rb &gt;&gt; /tmp/cron_test
  </code></pre>
  
  <p>I see the following entries in /tmp/cron_test. So it looks like the script indeed ran.</p>
  
  <pre><code>PROFILE: 
  i486-linux
  /usr/bin/firefox -jssh
  </code></pre>
  
  <p>But I couldn't figure out why I didn't see firefox opening up, for this automation to work. Here is <em>/home/raguanu/Dropbox/nettie.rb</em></p>
  
  <pre><code>#!/usr/bin/ruby -w
  
  require 'rubygems'
  require 'firewatir'
  require 'optiflag'
  
  module Options extend OptiFlagSet
      character_flag :d do
          long_form 'disconnect'
          description 'Mention this flag if you want to disconnect dataone'
      end
  
      flag :l do 
          optional 
          long_form 'admin_link'
          default 'http://192.168.1.1'
          description 'Dlink web administration link. Defaults to http://192.168.1.1'
      end
  
      flag :u do
          optional 
          long_form 'user'
          default 'admin'
          description 'Dlink administrator user name. Defaults to "admin"'
      end
  
      flag :p do 
          optional 
          long_form 'password'
          default 'admin'
          description 'Dlink administrator password. Defaults to "admin"'
      end
  
      flag :c do 
          optional 
          long_form 'connection_name'
          default 'bsnl'
          description 'Dataone connection name. Defaults to "bsnl"'
      end
  
      extended_help_flag :h do
          long_form 'help'
      end
  
      and_process!
  end
  
  class DlinkAdmin
      include FireWatir   
  
      def initialize(admin_link = "http://192.168.1.1", user = 'admin', pwd = 'admin')
          @admin_link, @user, @pwd = admin_link, user, pwd
      end
  
      def connect( connection_name = 'bsnl' ) 
          goto_connection_page connection_name
  
          # disconnect prior to connection
          @browser.button(:value, 'Disconnect').click
  
          # connect
          @browser.button(:value, 'Connect').click
  
          # done!
          @browser.close
      end
  
      def disconnect( connection_name = 'bsnl' )
          goto_connection_page connection_name
  
          # disconnect
          @browser.button(:value, 'Disconnect').click
  
          # done!
          @browser.close      
      end
  
      private
      def goto_connection_page( connection_name = 'bsnl')
          @browser ||= Firefox.new
          @browser.goto(@admin_link)
  
          # login
          @browser.text_field(:name, 'uiViewUserName').set(@user)
          @browser.text_field(:name, 'uiViewPassword').set(@pwd)
          @browser.button(:value,'Log In').click
  
          # setup &gt; dataone
          @browser.image(:alt, 'Setup').click
          @browser.link(:text, connection_name).click
      end
  end
  
  admin = DlinkAdmin.new(Options.flags.l, Options.flags.u, Options.flags.p)
  
  unless Options.flags.d?
      admin.connect( Options.flags.c )
  else
      admin.disconnect( Options.flags.c )
  end
  </code></pre>
  
  <p>Any help is appreciated.</p>