How do I execute this command using crontab? - unix

I run a list of tests using this command: "./kaboom testlist" which is written in Python.
This command can only be excuted in the directory /e/m/user/testing3/kaboom
I want to run this command every night at midnight using a cronjob. The only examples I've found online are prewritten shell scripts. So, I am not sure how to format this into a crontab so that it does what I want.
Any suggestions?

Say you want to run a job every night at 10pm then the crontab would look like:
00 10 * * * (cd /e/m/user/testing3/kaboom ; ./kaboom testlis ) > /tmp/cronjob.log 2>&1
Crontab entry just contains the commands you want to execute.
For examples on timings please check this geekStuff link.

Related

Crontab Redhat 8: Crontab will not run an R script that works perfectly otherwise

I'm currently trying to run a R file every minute through crontab. The R file take in a file from the previous directory and inputs into a sub-directory. If I just ./script.R the command will run fine, read and output all the data 100% accurately. However, in crontab it will not even run. I have tried a sample crontab to test if it was my crontab not working first, I wrote
* * * * * /bin/echo "foobar" >> /home/a/t/test.log
This command would correctly send foobar to the log.
However when I did
* * * * * /home/a/t/script.R >> /home/a/t/test.log
I would get no results within the test.log, nor would I get results in the subdirectory it should store in after being ran. I also did the script another way to see if the * were causing issues
*/1 * * * * /home/a/t/script.R >> /home/a/t/test.log
This also did not give any results.
After some research what I can understand is that there is likely an issue with paths. So to try to counteract that I did a cd command along with the R command as such:
*/1 * * * * cd /home/a/t/ && /home/a/t/script.R >> /home/a/t/test.log
Still, however, this has given 0 output. If I type
grep CRON /var/log/cron
I see cron trying to run the lines every minute, but again no output found anywhere, I dont think it is running and I can't understand why not.
Also in terms of path for the R script itself, within the R script I have the first line written something like
#!/bin/env Rscript -S --vanilla
which allows me to ./script.R and run it after a chmod as well.
This exact crontab commands also worked for me on my other laptops ubtunu vm, which is causing more confusion.
The command for running Rscript should be
Rscript path/to/Rscript.R
Please test the command by running it in your terminal. Once it run perfectly fine then just take the whole command and put it in crontab.

How do I add a cronjob to a makefile?

How do I add a cronjob to a makefile so when I compile a C program, I add a cron job to crontab so that program gets executed every minute:
Cron job I am trying to add:
* * * * * /Users/jenna/desktop/ && ./myProgram command_line_arg1
how do I add this to a make file ?
I believe it is a bad idea to add a crontab job from a Makefile. Adding a cron job is a sysadmin issue. Compiling your program is for a developer's hat.
If you insist on doing that, you might use crontab -l > mycrontab to list the current crontab jobs, then appending with
echo '* * * * * cd /Users/jenna/desktop/ && ./myProgram command_line_arg1' \
>> mycrontab
you probably want to make that more robust (perhaps use grep or awk) to avoid the appending if the crontab already contains that. BTW, you probably want to use $HOME/Desktop (and even that might not work on a French configured user, it would be $HOME/Bureau).
Then, set the new crontab with crontab mycrontab
At last, running something every minute seems suspicious to me. What is your program doing?
I would suggest to at the very least prompt the user before updating his/her crontab file....
Perhaps you want the at command....

scheduling meteor.js on crontab

I have a meteor.js application I've created to run locally on OSX on my laptop. Every so often, meteor stops running for unexplained reasons (like after the computer returns from sleep).
I'd like to schedule a process on cron to check every minute if meteor is working, and if it's not, launch it. I placed the following in my crontab:
* * * * * ps aux | grep meteor | grep -v grep || cd ~/path_to_my_meteor_project/; nohup meteor &
This command works at launching meteor when I enter it manually in terminal. But when scheduled in cron, it does not seem to do anything.
This is likely to be caused by the fact cron expects a binary file (or a script to launch) whereas, when typed in a terminal, your command is interpreted by bash, which understands logic such as ||.
In order to fix this, you will have to create a bash script containing the line of code working in your terminal, then ask cron to run it every minute.

Schedule R script using cron

I am trying to schedule my R script using cron, but it is not working. It seems R can not find packages in cron. Anyone can help me? Thanks.
The following is my bash script
# source my profile
. /home/winie/.profile
# script.R will load packages
R CMD BATCH /home/script.R
Consider these tips
Use Rscript (or littler) rather than R CMD BATCH
Make sure the cron job is running as you
Make sure the script runs by itself
Test it a few times in verbose mode
My box is running the somewhat visible CRANberries via a cronjob calling an R script
(which I execute via littler but Rscript
should work just as well). For this, the entry in /etc/crontab on my Ubuntu server is
# every few hours, run cranberries
16 */3 * * * edd cd /home/edd/cranberries && ./cranberries.r
so every sixteen minutes past every third hour, a shell command is being run with my id. It changes into the working directory, and call the R script (which has executable modes etc).
Looking at this, I could actually just run the script and have setwd() command in it....

Crontab : Running a jar file

I have a jar file that generates reports and i want to schedule to run it on every sunday,
For this purpose, i am using the crontab functionality on linux,
i have created the crontab entry using
crontab -e
45 15 * * 1 /usr/java/default/bin/java -jar /home/name/example/withouttimer.jar
but the job does not run as it should, Can you please help me find the issue with it,
Is there a way to check crontab logs?, thanks
Probably the profile used when running cron jobs does not have some variables set (JAVA_HOME? CLASSPATH?)
Do a crontab that does printenv > myfile.txt and check what is defined.
As a last test, create a .sh file and run it, that does
echo 'hello'
printenv
echo 'goodbye'
and see if redirecting the execution of your script to a log shows something.
That job runs at 3:45 pm on every monday (0 is for sunday)Are you sure you are checking it at right time?
Try running a dummy program at lesser interval to check whether its working.
Finally got the solution,
There was a couple of things that i was doing incorrectly,
The timezone of the server was different, so i had to set it accordingly.
The jar was not able to locate the input file(bad location), had to fix it.
Works gr8 now, thanks for the suggestion on adding MAILTO= , helped in debugging.

Resources