Issues with cron - unix

I'm really stuck. I've used cron on many machines, but I simply can not get it to work on an Ubuntu server. I've tried everything I can think over the weekend and I'm baffled. I'm hoping someone can help me out.
I can verify that cron is running via pgrep cron. However, pgrep crond returns nothing. I am trying to run a simple shell script (test.sh) with cron:
#!/bin/sh
/usr/bin/touch /home/jarvis/test.txt
I have run chmod +x on the shell script and my crontab looks like this:
01 * * * * /home/jarvis/test.sh
I also have a new line ending after the line.

Try redirecting all output to a file and see if there are any error messages that can help you diagnose the problme, i.e.
01 * * * * /home/jarvis/test.sh > /tmp/jarvis_test.log 2>&1
Also, if you created any of those files from a windows environment, don't forget dos2unix filename
edit
My point is that you won't know for what your script is doing in the crontab environment unless you see if it is outputing an error message. Error messages also go to local crontab user's email, so try mail (as the same user) and see if you have a bunch of messages from your crontab.
pgrep crond returning nothing sounds like the problem, but I'm not a sysadmin. Maybe you want to flag this and ask for moderator to move to https://serverfault.com/
I hope this helps.

I think it is related to the user permissions. Try putting in default crontab hourly,weekly files, if it works there then your cron is good. Also, check /var/log/messages for any cron entry. View /etc/crontab for detailed configuration.

Related

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....

R script as cronjob not executing

I've created a short R script that continuously downloads data from twitter using the streamR package. This script is supposed to run on a standard Amazon EC2 server running Ubuntu 14.04. When testing it in the standard command line, it runs fine. However, it is not run as specified in the cronjob. I used the following command:
sudo crontab -e
and then added the following line to the file
0 * * * * Rscript /home/mydirectory/docs/phd-research/data-collection/cron-script.R
in the hope that it would execute the R script every hour.
Is there anything I might have got wrong with the permissions? I've already checked that cron is running and I chmodded the directory the r script is supposed to write to to 775.
Thanks in advance!
OK - it turns out I used the wrong command to call up the crontab. The directory it was supposed to be working in was owned by user rather than root, so calling a root crontab didn't work.
The proper command for editing the crontab is the following:
crontab -u user -e
The Rscript didn't require the full path, it worked with both.
The $PATH$ is not known (i.e. the directory of Rscript is not part of the standard $PATH$) during the execution of a cronjob. Writing the full path to Rscript will work:
0 * * * * /.../Rscript /home/mydirectory/docs/phd-research/data-collection/cron-script.R

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.

cron job not creating logs

I am trying to execute some sql statements using an unix script. The script is placed in crontab to run everyday at 12.00 midnight and get the output in a log file.
Though my script is running and I can see the changes in DB but the log file is not generating. However manually running the script is generating the log file. Please suggest a solution.
now=`date "+%d%m%y"`
LOG="table_partition_$now.log"
test=`sqlplus -s ${USER}/${CPWD}#${DB} << THEEND > $LOG
...
...
...
exit
This is my code snippet. Please suggest
sqlplus has no closing `
Also, can you say whether the script runs correctly outside of cron? If it only fails in cron, you may want to call
env > /tmp/mylatestslog.txt
at the start and compare the differences with your local environment. (May be differences in the user, or variables used from you personal .bashrc).
(PS. also edited the question to show one command per line.)

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