Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
When I execute my cron manually everything seems to work. However when it runs by cron it seems to run twice. In my deployment script I have the following two lines to add my crons:
/usr/bin/crontab -l | { /bin/cat; /bin/echo "* 3 * * * /etc/app/execute.py"; } | /usr/bin/crontab -
/usr/bin/crontab -l | { /bin/cat; /bin/echo "* 0,2,4,6,8,10,12,14,16,18,20,22 * * * /etc/app/solr.py"; } | /usr/bin/crontab -
Is there any reasonable reason why my CRON might be running twice on my debian server? I have no idea what might be causing this or how to debug it.
In my Crontab I have this:
* 3 * * * /etc/app/execute.py
* 0,2,4,6,8,10,12,14,16,18,20,22 * * * /etc/app/solr.py
You can debug this by adding something like
; echo $(date) ; echo "Cron line one" >> /root/cronlog
That way you can see which line was executed when.
Also, how do you edit your cronjobs? With "crontab -e" or by directly editing the files? If you edit the files directly (which I don't recommend), then please compare the content of the files with the output of "crontab -l".
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I've been playing around with getting crontab to run a tar command on a scheduled basis however it appears to not actually run the task at the intervals at all.
The line of code I've put into my crontab file is as follows.
1 * * * * tar cvf backup.tar . >> ~/testcron.log
The tar command works by itself if I run it in terminal so I'm not sure why this doesn't run.
Thanks
There are two things here which I can imagine being problematic:
If this is part of a file in /etc/crontab.d or part of /etc/crontab, cron expects a user name in the 6th column. So it would be something along the lines of:
1 * * * * root tar cvf backup.tar . >> ~/testcron.log
You might want to replace . with a proper absolute path. I would not be sure what the current directory is when cron executes the cronjob, so just use an absolute path.
Unable to post as a comment
cron PATH variable may be different from your user PATH variable
If this is the case, you will either have to specify the absolute path to the tar executable or export your local PATH to the crontab
More information here
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
Here is my crontab entry:
* * * * * /home/ec2-user/Test/test_thing.sh
Here is the script, test_thing.sh:
echo "asdf" >> ./bla.txt
When I run it manually, it does generate the "bla.txt" file. However, it does not automatically do so (create the "bla.txt" file within the /Test/ directory) with the crontab.
I have also checked my /var/log/cron file and I see that it is executed every minute, but not sure if it's running into an error or not.
If it is important, I am running this on an Amazon ec2 server, specifically the Amazon Linux AMI.
Edits:
I have also done chmod +x test_thing.sh to make sure it is executable.
The cronjob runs from home directory by default. So you should see the file to be created under /home/ec2-user or /root if you run it by root account.
If you need generate the new file with the nominate path, one way is to use absolute path as #yftse said. The other way is
* * * * * cd /home/ec2-user/Test/; bash /home/ec2-user/Test/test_thing.sh
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I need to run a shell script in every 10 minutes.
I am appending the output in a log file every time script runs.
I need to stop the script from running once the size of the log file reached to 10 MB.
how can this be achieved , please help !!
./test.sh >> log_file
maximumsize=10000 #KB
while :
do
./test.sh >> log_file
actualsize=$(du -k log_file | cut -f 1)
if [ $actualsize -gt $maximumsize ];then
echo "logsize exceed.stop."
break
fi
sleep 600
done
You should modify your test script : put your process into a function, add your function into a loop, condition of the loop (size of your log file under 10MB) and at the end of the loop add a sleep 600 to wait for ten minutes
You might add to the start of your test.sh script a test, if the log file > 10MB then do not run (exit), or you could archive (maybe gzip -9 or xz -9) the log, if it's all text output then it should compress a LOT. Or you could pipe the script's output through gzip to compress it right away.
And also use cron/anacron to run the script regularly, like add */10 * * * * user test.sh to /etc/crontab...
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
Ok, so I'm trying to set cron to run a bash script at a certain time. My bash script is essentially this
#!/bin/bash
espeak -g 3 "this is my text"
So from there, I went to the crontabs, and added in
*/1 * * * * /path/to/my/script.sh
to see if it would run, but it didn't do anything. I changed the script to
#!/bin/bash
echo "this is my script"
to see if that would do anything, but no avail. Any help? Thanks.
Try to run the script manually and see if it echos out: bash /path/to/my/script.sh
Does the file have the correct permissions?
Try Outputting errors to a log file: */1 * * * * /path/to/my/script.sh > /path/to/my/error.log 2>&1
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I see a bunch of tutorials for cron commands like
0 */5 * * * /some_sript.sh
But what file do I put this line of text in?
From tag:crontab info
Basic commands
crontab -e Edit crontab.
crontab -l Show crontab current information.
Also, you'd better write
0 */5 * * * /bin/sh /some_sript.sh
instead of
0 */5 * * * /some_sript.sh
That is, indicate the binary executing the script.
You just need to run "crontab" command to edit the cron table. Try to "man crontab".