I am trying to run a selenium ruby script on Chrome through crontab but don't see anything run.
I tried the following as suggested in other questions:
crontab -u shamanth -e
Added the following
MAILTO=""
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
export DISPLAY=:0 google-chrome
47 13 * * * /usr/bin/ruby ~/Desktop/script.rb
From the cron logs /var/log/syslog, I see that the script has started (I put some print messages in the beginning of the script) but I don't see chrome launching.
Permissions have been given to the script file.
Most likely the problem is with the path you are setting: crontab works in a very limited environment, where paths like ~ are not understood.
For that, instead of saying
* * * * * /usr/bin/ruby ~/Desktop/script.rb # NO!
# ^
say
* * * * * /usr/bin/ruby /home/your_user/Desktop/script.rb # YES!
# ^^^^^^^^^^^^^^^
Related
I want run my script from the crontab on Mac OS, but I'm getting an error:
ruby: Operation not permitted -- /Users/vitalii/Desktop/Home/update/update.rb (LoadError)
My preferences for the cron task and settings are created using rvm cron setup:
#sm start rvm
PATH="/Users/vitalii/.rvm/gems/ruby-2.4.1/bin:/Users/vitalii/.rvm/gems/ruby-2.4.1#global/bin:/Users/vitalii/.rvm/rubies/ruby-2.4.1/bin:/Users/vitalii/.rvm/gems/ruby-2.4.1/bin:/Users/vitalii/.rvm/gems/ruby-2.4.1#global/bin:/Users/vitalii/.rvm/rubies/ruby-2.4.1/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/vitalii/.rvm/bin"
GEM_HOME='/Users/vitalii/.rvm/gems/ruby-2.4.1'
GEM_PATH='/Users/vitalii/.rvm/gems/ruby-2.4.1:/Users/vitalii/.rvm/gems/ruby-2.4.1#global'
MY_RUBY_HOME='/Users/vitalii/.rvm/rubies/ruby-2.4.1'
IRBRC='/Users/vitalii/.rvm/rubies/ruby-2.4.1/.irbrc'
RUBY_VERSION='ruby-2.4.1'
#sm end rvm
* * * * * ruby /Users/vitalii/Desktop/Home/update/update.rb >> /Users/vitalii/Desktop/logfile.txt 2>&1
I gave each file the rights to execute with chmod 777, but there are no changes and the error is repeated.
The contents of the file update.rb are
puts 'Hello, World!!!'
Can someone tell me what's going on and what I'm doing wrong ?
I found solution, since I use Mojave.
I need to make additional settings in the system. Who would have thought ...
enter link description here
This turns out to be a problem, since you need to allow permissions for cron.
And correct run command for crontab -e, this
* * * * * /bin/bash -l -c 'ruby /Users/vitalii/Desktop/Home/update/update.rb'
There is a little difference when setting crontab job via crontab -e or putting them in /etc/crontab
$ crontab -e
# m h dom mon dow command
* * * * * echo ok
$ nano /etc/crontab
# m h dom mon dow user command
* * * * * root echo ok
Is this the case?
I'm using a osx and I created a ruby script in the path: /Users/diogo/workspace/outros/crawler_trf with name get_news.rb
So I tried to execute it via crontab with the following line: */1 * * * * 'ruby /Users/diogo/workspace/outros/crawler_trf/get_news.rb' > /tmp/crawler_trf.out and I've got the error: /bin/sh: ruby /Users/diogo/workspace/outros/crawler_trf/get_news.rb: No such file or directory
I really had searching for my answers for long but I didn't found nothing.
cron is feeding your command:
'ruby /Users/diogo/workspace/outros/crawler_trf/get_news.rb' > /tmp/crawler_trf.out
to /bin/sh as-is but there is no 'ruby /Users/diogo/...' command, there probably is a ruby command that can take /Users/diogo/... as an argument though so drop the quotes:
*/1 * * * * ruby /Users/diogo/workspace/outros/crawler_trf/get_news.rb > /tmp/crawler_trf.out
You might want to include the full path to ruby as well or at least make sure there's a PATH setting in your crontab.
I followed some other posts in stackoverflow and successfully setup cron with RVM using rvm cron setup and injected some ENV to the crontab file.
When I was troubleshooting why the dotenv gem is not working, I realised the following:
I placed my test.rb in file path /home/myuser/ruby/test.rb and had my crontab file as shown below:
* * * * * ruby /home/myuser/ruby/test.rb >> /home/myuser/ruby/output.log
and when I puts the output of the test.rb with Dir.pwd. The output states that the rb is run in the /home/myuser/ directory instead of /home/myuser/ruby directory.
While I had a hotfix by manually changing the path. But I wonder why it is the case.
By default, cron tasks of a user are executed from the user's home directory. In order to execute the script from proper directory, you have to "cd" to it.
Consider changing your crontab to:
* * * * * cd /home/myuser/ruby && ruby ./test.rb >> /home/myuser/ruby/output.log
Good luck!
According to #Pawel Dawczak who left the answer in the comment.
the solution is to rewrite the statement in crontab as
* * * * * cd /home/myuser/ruby && ruby test.rb >> /home/myuser/ruby/output.log
Thanks!
I use Rails 4 + whenever 0.9.2 on Mac os
But it didn't work at all. it seems never run the script
Whenever config file
every 1.minute do
command "/Users/get_price_and_send_mail.rb"
end
Crontab
* * * * * /bin/bash -l -c '/Users/get_price_and_send_mail.rb'
And If I edit the crontab manually, crontab -e
and save it with wq!
"crontab.f3SIocnMWc" 5L, 349C written
Then crontab -l gave me the original result, it didn't changed.
where to check the logs of cron job?
I did pgrep cron it gave 2358
What does it mean?
0 02 * * * /feedbatch/application/scripts/baselineUpdate.sh
0 13 * * * /feedbatch/application/scripts/baselineUpdate.sh
#0,10,20,30,40,50 * * * * /feedbatch/application/scripts/partialUpdate.sh
*/2 * * * * /feedbatch/application/scripts/partialUpdate.sh
15 0 * * * /usr/sbin/logrotate -s $HOME/logrotate.status -f $HOME/endeca-logrotate.conf
16 0 * * * /usr/sbin/logrotate -s $HOME/outputrotate.status -f $HOME/endeca-outputrotate.conf
Your scripts are in this location -- /feedbatch/
Please check whether a directory named feedbatch is there in / . and whether a normal user has permission to run the scripts inside it if the directory exists. Try to put all your scripts in a new bin folder.. thats a good practice..
Other scripts are in /usr/sbin/....
Here also the permission may be an issue.
Try to put all these inside the root crontab. So that there wont be any permission issues.
Also check if your username is there in /etc/cron.allow and /etc/cron.deny.Dont worry If these two files are not present. But if these files are there, please make sure that your name is there in cron.allow and not there in cron.deny
to access the root crontab do the following
su - root
crontab -e
The cron daemon will log to default system logger. So it will be logged to messages or syslog.
You can configure the rsyslog to log all cron log output separate file. This is a bit depending of your linux distribution. As follow an example to write cron log to separate file for Ubuntu12.04:
edit /etc/rsyslog.d/50-default.conf (uncommand the cron.* line)
...
auth,authpriv.* /var/log/auth.log
*.*;auth,authpriv.none -/var/log/syslog
#cron.* /var/log/cron.log
#daemon.* -/var/log/daemon.log
...
restart cron daemon.
Your cron output should be logged to /var/log/cron.log now.
That should get your an better overview about "cron doing".