1

I am attempting to automatically start my Smashing Dashboard when my Raspberry Pi boots. I plan to run a script through the @reboot option in crontab (similarily to how I already automatically shutdown the dashboard). However I'm having trouble running the script below.

    command  = 'cd "/home/pi/test"' 
    command2 = 'smashing start'


    system "echo hi"
    system command
    puts command
    system "echo Movement"
    system command2
    puts command2

The script itself is just being run from the terminal just now using 

    ruby /home/pi/start_up.rb. 

Starting Smashing appears to fail because the working directory is not moved through the cd "home/pi/test"command as when the script is run I recieve the following error

Could not locate Gemfile or .bundle/ directory

There certainly is a Gemfile in the Test directory. This is the same error I get if I run smashing start directly from the home/pi folder suggesting that folder is never moved. Is there a correct way to do this? Any advice would be greatly appreciated.

1 Answers1

1

Your cd "/home/pi/test" didn't work because cd is a shell built-in. It changed the directory in the shell, but not in Ruby.

To change the directory in Ruby, use

Dir.chdir '/home/pi/test'

Each process has its own current directory. Ruby's Kernel#system spawned a shell process (probably /bin/sh) to run the command, then waited for the shell to exit. The shell changed directory, then exited. Ruby never changed directory.

George Koehler
  • 1,290
  • 14
  • 20