Working in Debian 8.5.
The installed cronjob looks like this:
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
*/1 * * * * /usr/local/bin/MySript.sh
#---------------------------------------------------------------
The bash script looks like this:
#!/bin/bash
cd /home/Path/to/executable/C/program
sh -c "xterm -e ./Cprogram" &
exit
When I execute the C program with ./MyScript.sh, the bash window pops up and the C program runs.
Cron won't run the script. The Daemon is running and cron is executing, as I see in /var/log/syslog
I overviewed all priviliges and I do everything as root.
I'd be very happy for any advice. Thanks in advance, JS
Related
I need to run daily a shell script which contains the steps of the model Weather Research Forecasting. I used cron for this. The first executable of the script (ungrib.exe) works perfect, but the second executable "metgrid.exe" it's not working at all. When I run the script in the terminal of linux works perfectly.
This is an example (summarized) of my script:
#!/bin/bash
bash
./link_grib.csh /home/user/WRF/GFS/
./ungrib.exe
ln -s metgrid/METGRID.TBL.ARW ./METGRID.TBL
./metgrid.exe <- not running with crontab
The way that I configure my crontab is:
crontab -e
SHELL=/bin/sh
00 01 * * * /home/user/WRF/scripts/WRF_scripts.sh
Any idea?
I added in my crontab the full path of libraries related with the execution of WRF.
LD_LIBRARY_PATH=$LD_LIBRARY_PATH
I read the other related topics but they didn't help me.
I have a shell script which checks if my python script is not running,it will run it. Otherwise it will just skip and do nothing.
It totally works when I use:
bash myshellscrip.sh
And I get the result that I want which is doing some tasks and sending emails to some correspondents. However, when I try to run this particular shell script on crontab, it doesn't send out the emails and doesn't do the other tasks.
I tried the following on crontab and none of them worked.
* * * * * /bin/bash /path/to/my/script/myshellscrip.sh
* * * * * /bin/bash /path/to/my/script/myshellscrip.sh >> /some/other/path/output.txt
When I save the changes into 'output.txt' file, it creates the file but it doesn't send the emails or doing other tasks.
I also tried the option of reboot because I need this program to run at start up too, and this didn't work:
#reboot /bin/bash /path/to/my/script/myshellscrip.sh
Does anyone know how to fix it?
EDIT:
As I was checking with the simplest shell scrip like:
#!/bin/sh
/usr/bin/python /home/pi/DCA/code.py
My crontab wouldn't have any output in my output.txt file although my code.py have something printing out, too.
However, when I use a very simple python code for example only a 'print' statement it will run and save the output into output.txt.
Seems like your shell script crashes / stops before it can do something (possibly due to the environment being different or permission issues). You can check /var/log/syslog to find out.
You could try removing /bin/bash, I don't think that's necessary?
Run the cron job in debug mode. for that, Add -x to the bash command on the cronjob and save their output in the file.
bash -x /path/to/script.sh >> /path/to/the/output.txt
You can find the problem.
Apparently crontab was running my script several times. So I tried to use different locking mechanisms to put a lock around my scrip but only using flock worked for me. In my crontab I added this line:
* * * * * /usr/bin/flock -n /tmp/ms.lockfile /bin/bash /path/to/my/script/myShellScript.sh
I have a ruby script that I have tested to be working that I would like to run as an hourly cron but cannot seem to get it firing properly.
The last thing I have tried was placing the line:
ruby ~/ruby_script.rb
in /etc/cron.hourly
Said ruby script is located in the home directory with:
#!/usr/bin/env ruby
as its top line.
I have looked into ruby & cron resources but they most seem to be for reoccurring tasks in a Ruby on Rails environment when I just want the script to run in my ubuntu environment. I have double checked that rails is installed as well.
I have had a lot of fun learning more about ubuntu over the past few months and will truly appreciate any assistance I receive here. Thank you in advance.
Try to use current user crontab
$ crontab -e
Add new cron job
0 * * * * /bin/bash -l -c 'ruby ~/ruby_script.rb'
Using bash command to run helps to get env variables during script execution.
(for tests change 0 to * - script will try to run every minute)
To log errors you can try to add command:
0 * * * * /bin/bash -l -c 'ruby ~/ruby_script.rb >> ~/ruby_script.log 2>&1 &'
Hope it helps.
I want to execute cucumber in my computer.
in terminal I can execute cucumber ( cucumber feature )
and I can using crontab
but, I can't crontab execute shell script, shell script execute jar, jar execute cucumber in my environment
You can write a shell script to invoke cucumber command, like this:
/home/test.sh
#!/bin/bash
cd your_work_directory
cucumber -p test
Then execute 'crontab -e' command to edit your cron job, because crontab shell is not login-shell, so you need code like this:
0 1 * * * bash -lc '/home/test.sh'
If your cucumber need GUI environment, your code should be like this:
0 1 * * * env DISPLAY=:0 bash -lc '/home/test.sh'
In my crontab file I execute a script like so (I edit the crontab using sudo crontab -e):
01 * * * * bash /etc/m/start.sh
The script runs some other scripts like so:
sudo bash -c "/etc/m/abc.sh --option=1" &
sleep 2
sudo bash -c "/etc/m/abc.sh --option=2" &
When cron runs the script start.sh, I do ps aux | grep abc.sh and I see the abc.sh script running.
After a couple of seconds, the script is no longer running, even though abc.sh should take hours to finish.
If I do sudo bash /etc/m/start.sh & from the command line, everything works fine (the abc.sh scripts run for hours in the background until they complete).
How do I debug this?
Is there something I'm doing that is preventing these scripts from running in the background until they are done?
The program(s) you're starting might be expecting a terminal to send their output to, or receive input from.
If you set the MAILTO= variable, and you have a sendmail(-like) daemon installed, you will get an email with the error message(s) it prints, if there are any:
MAILTO=your#email.address.here.com
01 * * * * bash /path/to/something.sh
Another way to debug would be to run the script from the command line, while redirecting all inputs and outputs:
$ sudo bash -c "foo.sh" > output_file 2>&1 < /dev/null
Also, the system log files (usually found in /var/log) might contain useful hints.