ruby - Discrepancies when executing a command in Rails controller vs Rails console -


i trying run df command display statistics of disks attached server. however, returns size of disk 0. if run same command in rails console within production environment, returns size of disk.

here's how code structured,

class disk   def self.metrics     `df -h`   end end 

and how call in controller,

 class diskcontroller    def metrics      @metrics = disk.metrics    end  end 

but returns nil when try see result in view. same command works in rails console.

i've tried using system, popen returns same result.

also, same thing works in development (mac osx) not in production (linux ubuntu).

your console running under user have logged in. rails app running under user, dedicated run web server. believe call whoami within controller code show user name. user restricted run df command. though not recommended, possible solution grant user execute df command (via /etc/sudoers.)

i go approach, though. add cron job, execute df -h on behalf of permitted user , put output inside text file within project tree. controller might read file show disk usage info.

i understand information might obsolete, since 1 might execute cron job each, say, minute, should acceptable. advantage of approach web server still won’t have access system commands.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -