Editing crontab using bash script - bash

I have a list of crontab entries:
0 * * * * /home/tomcat/abc.sh
0 * * * * /home/tomcat/def.sh
I want to perform an action through a bash script and it requires one of the cron jobs to be disabled.
#0 * * * * /home/tomcat/abc.sh
0 * * * * /home/tomcat/def.sh
How can I comment a single cron job using bash script?
Please help. Thanks!

That's kinda dangerous in my book, I wouldn't recommend doing that. Instead, I'd update your script so that it creates a file (like /tmp/MY_SCRIPT_LOCK or whatever) at the start and removes the file at the end. Then just update the cron job so it doesn't run if it finds the file:
0 * * * * test -f /tmp/MY_SCRIPT_LOCK || /home/tomcat/abc.sh

If you want to add a comment (#) at a particular line you can use -
Third line:
sed '3s/^/#/' filename
You can save this as new file or use output redirections.

Related

Scheduled Cron Expressions does not work as expected

I'm tring to run a function every 10 minutes.
According to the documentation, it is stated that e.g ("0 0/5 * * *?") Runs every 5 minutes since the program started, but why when I change 5 by 10 ("0 0/10 * * *?"), the function does not run every 10 minutes e.g (10:10 - 10:20 - 10:30)
Is it really me who misunderstands the Cron Expressions or the syntax is wrong.
here is typo in :
"0 0/10 * * *?"
should be
"0 0/10 * * * ?"
here is the useful resource CronMaker is a utility which helps you to build cron expressions. CronMaker uses Quartz open source scheduler.

Execute job in Jenkins every X minutes and in a time range

I would like to execute a job in Jenkins with a cron every 15 minutes between a time range.
I tried with this:
15 8-19 * * 1-5
But it execute hourly. I want this:
Every 15 minutes From 8AM to 7PM and from Monday to Friday.
From the Jenkins' cron syntax:
* specifies all valid values
M-N specifies a range of values
M-N/X or */X steps by intervals of X through the specified range or whole valid range
To allow periodically scheduled tasks to produce even load on the system, the symbol H (for “hash”) should be used wherever possible.
According to the rules above you can use the following:
H/15 8-19 * * 1-5
If I under Stand Your question all you need is something like below :
*/15 4,7 * * * /bin/sample >/dev/null 2>&1
i use crontab generator Online to get crontab configuration
*/15 8-18 * * 1-5
This will give you what you want, but the last execution will be at 18:45.
*/x means 'execute once in a given 'x' minutes/hours/etc

Crontab is not running on mac osx 10.9.3

I would like to open a URL using crontab in the terminal every minute for example. I also tried "cronnix" and "lingos" but non of the methods work. My mashine simply does not execute the command. I did
crontab -e
then I inserted the line
1 * * * * open http://www.google.de/
terminal says it is installing the new cron job. But then nothing happens. What do I have to do? Thanks.
1 * * * *
means the job will execute every first minute of every hour of every day of every week of every month, for example at 09:01, 10:01, 11:01, ...
*/x * * * *
will execute the job every x'th minute of every hour of every (yadda yadda...).
For example, for x=5 the job will execute at 09:05, 09:10, 09:15, and so on, but also of course at 10:05, 10:10, 10:15, ...
For x=1 it is the same as just saying
* * * * *

How can I run the kippo honeypot on rasbperry pi using crontab?

I've tried several different implementations as follows:
05 11 * * * cd /home/pi/kippo/; ./start.sh
05 11 * * * /home/pi/kippo/start.sh
05 11 * * * bash /home/pi/kippo/start.sh
05 11 * * * sh /home/pi/kippo/; ./start.sh
I've tried this crontab entry and in order to test if my timezone is correct. I've also tried creating text files to ensure that my crontab is functioning well.
05 11 * * * touch /home/pi/bin/hellotestkippo.txt
I've created this text file to ensure and test if at the same time I'm trying to run Kippo can be created to serve as a checker that cron does it's job.
The problem is the text file was created but kippo didn't start at all.
Please help me on this matter. Thanks.
try this commond:
sh /home/pi/kippo/start.sh
Edit your /etc/rc.local and add:
su - pi -c kippo/start.sh

BASH - how do i detect the file date time is changed so do a copy or move now once its done?

I have a static directory: /var/tmp/files
This directory is only shared with users for upload/download via SFTP, it has some static file names such as:
recording-security.frontdoor.avi
recording-security.backdoor.avi
recording-security.parkingspace.avi
....
from another PC via SFTP those files are getting removed/edited/updated/added etc
Now another path: /var/www/html/livevideo-stream/
those files are copied, moved from /var/tmp/files
How can i using BASH read those files were edited or newly added or overwritten? So, that my script can move valid contents from /var/tmp/files to livevide-stream only those which has been modified or newly added etc?
$ crontab i have:
0 7 * * * /var/tmp/finishit.sh
0 8 * * * /var/tmp/finishit.sh
0 9 * * * /var/tmp/finishit.sh
0 19 * * * /var/tmp/finishit.sh
0 20 * * * /var/tmp/finishit.sh
$ cat /var/tmp/finishit.sh
#!/bin/bash
cd /var/tmp/files
while :
do
"""
how do we now validate those files which was modified or changed or newly added and place them in that directory?
"""
# echo $1 $2
cp -R /var/tmp/files/* /var/www/html/livevideo-stream/
sleep 1
done
Your cron will launch your script several times per hour, and your script does not terminate due to the while : loop... You will end up with a lot of background scripts trying to copy stuff ever second.
You should simply replace the whole script with
rsync -vaq /var/tmp/files/* /var/www/html/livevideo-stream/

Resources