this is my third time trying to post this. I am having some trouble running my Ruby Script using a crontab.
Below is my file tree
rubyUbuntuIssue
├── logFile.txt
├── RubyFile.rb
├── Script_Files
│ ├── logFileTwo.txt
│ ├── scripttwo.sh
│ └── trigger_file.rb
└── trigger.sh
This is my crontab file
SHELL=/bin/bash
PATH=/usr/sbin:/usr/bin:/sbin:/bin
*/1 * * * * sh /home/ubuntumike/Documents/rubyUbuntuIssue/trigger.sh >> /tmp/mybackup.log
This is my trigger.sh
file
set -x
set -e
SHELL=/bin/bash
#PATH=/home/ubuntumike/.rvm/gems/ruby-2.1.5/bin:/home/ubuntumike/.rvm/gems/ruby-2.1.5@global/bin:/home/ubuntumike/.rvm/rubies/ruby-2.1.5/bin:/usr/local/sbin:/usr/local/bin:/usr/s$
cd /home/ubuntumike/Documents/rubyUbuntuIssue
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
# or use an absolute path instead of $HOME, just make sure the script get sourced
# after that you can choose correct ruby with rvm
rvm use ruby-2.1.5
ruby RubyFile.rb;
ruby Script_Files/trigger_file.rb 2>&1 >> /tmp/errors.txt;
sh Script_Files/scripttwo.sh
echo "The present working directory is `pwd`"
echo "$(date) running trigger.sh file"
echo "`ruby -v`"
When I run trigger.sh
directly from terminal everything works perfectly, however when run using crontab
only the RubyFile.rb
will run which is on the same level as the shell file
Ok so heres what should happen when trigger.sh
is executed the 3 scripts
RubyFile.rb
,
scripttwo.sh
,
trigger_file.rb
should run.
When I run this directly from terminal all 3 scripts work as expected.
When I run this using crontab RubyFile.rb
and scripttwo.sh
will run however trigger_file.rb
will not run. I simply don't have a clue what I am doing wrong.
If you want you can have a look at the exact code on GitHub https://github.com/omearamike/rubyUbuntuIssue .
If anyone can offer some guidance it would be much appreciated as I am completely lost and ran out of options.
Current response in terminal when trigger.sh
is run.
+ set -e
+ SHELL=/bin/bash
+ cd /home/ubuntumike/Documents/rubyUbuntuIssue
+ [[ -s /home/ubuntumike/.rvm/scripts/rvm ]] trigger.sh: 7: trigger.sh: [[: not found
+ rvm use ruby-2.1.5
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for an example.
+ ruby RubyFile.rb
+ ruby Script_Files/trigger_file.rb
+ sh Script_Files/scripttwo.sh
Script_Files/scripttwo.sh: 10: Script_Files/scripttwo.sh: date: not found
running scripttwo.sh file...........................SUCCESS
+ pwd
+ echo The present working directory is /home/ubuntumike/Documents/rubyUbuntuIssue
The present working directory is /home/ubuntumike/Documents/rubyUbuntuIssue
+ date
+ echo Wed Oct 7 22:10:48 IST 2015 running trigger.sh file
Wed Oct 7 22:10:48 IST 2015 running trigger.sh file
+ ruby -v
+ echo ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]