I am executing below command to remotely disable and enable cron job on linux server but command not disabling cron job on remote server.Although it's working when trying on same server.
ssh mysql#$pas_ser_name "crontab -l | sed "/^[^#].*$job_name/s/^/#/" | crontab -"
Could anyone help on same.I want to enable and disable linux job remotely with job name.
crontab -l | grep -v 'wget php -q http://www.example.com/event_reminder.php' | crontab -
crontab -l lists the current crontab jobs
grep -v filter some line
crontab - adds all the printed stuff into the crontab file.
you can use this, I hop it will help you.
Related
I wanted to run cron and run a few script started at a time set in crontab. I've installed cron on my docker container and wanted to add some crontab lines and cron starting in separate script. Here are fragments of my configuration
supervisord.conf
[program:cron]
command=/stats/run-crontabs.sh
/stats/run-crontabs.sh
#!/bin/bash
crontab -l | { cat; echo "11 1 * * * /stats/generate-year-rank.sh"; } | crontab -
crontab -l | { cat; echo "12 1 * * * /stats/generate-week-rank.sh"; } | crontab -
cron -f -L 15
and when it is time to run script by cron, I can see only that error in container logs
2022-01-29 01:12:01,920 INFO reaped unknown pid 691343
I wonder how I can run script by cron on docker container. Do I need supervisor?
EDIT: As #david-maze suggested I've done it like he commented and run cron as container entrypoint and problem is the same
Thank you for your help
Ok, I have to post an answer. I've realized that scripts working well, but it saved reports in system root directory, not on directories that I wanted.
It were because of lack of environment variables
More you can read those topic,
Where can I set environment variables that crontab will use?
but I've resolved my problem with adding that line at the start of 'run-crontabs.sh' script
crontab -l | { cat; echo "$(env)"; } | crontab -
Ubuntu
In my Ubuntu VM, I have configured a cronjob
cat /var/spool/cron/crontabs/*
MAILTO="myemail#gmail.com"
* * * * * python /home/forge/web-app/database/backup_mysql.py
I checked pgrep cron I got number printing out fine.
It been 5 mins now, I don't see any email send to me.
I don't see any backup file is being generated.
I have a feeling that this cronjob never got run.
How do I debug this ?
Do I need to restart some kind of service ?
Could you please check the cron service.
service cron status.
And check the cronjob logs to check it is running or not
tail -f /var/log/cron | grep username
Check the cron
crontab -e -u username
And also check permission.
chmod +x <file>
I created a shell script to check a tomcat instance status. If the instance is not started, then start it:
if [ `ps -ef | grep 'travelco' | grep -v grep | wc -l` -eq 0 ];then
sudo /home/q/tools/bin/restart_tomcat.sh /home/www/travelco/
else
echo 'travelco started'
fi
Then I tested the script and it worked well. But after I added it as a crond job, this script didn't work as expected.
I used crontab -e, and added
*/1 * * * * /home/yuliang.jin/travelcoCheck.sh
After that, even though I can see the script executed in the crontab log(sudo tail -f /var/log/cron), the tomcat instance was not started. Why?
There's a sudo in your script but are you sure that your current user has the permission to execute /home/q/tools/bin/restart_tomcat.sh without password authentication?
You should add the script to /etc/sudoers to allow your current user to execute the script without password, or you can just sudo crontab -e to run the script as root (and don't forget to delete sudo in your script if you do so).
If there is any other option, don't sudo in a cron job.
travelcoCheck.sh will be matched by the grep travelco and is not cancelled by the grep -v grep, so wc -l will be at least 1 always. So restart_tomcat.sh will not run.
(As a side note: whether or not your ps-parsing stack gets caught by ps is something of a dark art and is full of corner cases and race conditions and generally difficult to get to work right. Stuff like this is why dbus was invented.)
I'm doing server migration in sun solaris OS. And I have to migrate crontabs also with that. New server have fresh installation of solaris. In usual way while I type crontab -l it shows the existing cron content.
But while I type crontab -e it fail to load the editor. How can I overcome this issue?
This can be fixed by exporting editor variable with value vi. So run following command and then run crontab -e
export EDITOR=vi
crontab -e
I developed a script in which I add lines to the crontab file with echo command and I remove lines with sed command.
I do not know the risk of that especially that I find in some web site that we have to edit crontab file with
crontab -e
What is the risk of does not using crontab -e?
Are there a risk that my edit will not taken account in the cron
schedule?
Should I restart cron with /etc/init.d/cron restart?
The main risk to not using crontab to edit or replace cronfiles is that directly writing to the cronfile (including using sed to do so) does not lock the file, and therefore two simultaneous edits could have unpredictable and even disastrous consequences.
You don't have to use crontab -e; the following forms of editing are semi-safe, in the sense that they won't randomly combine two edits. (But they are still unsafe; an edit could be overwritten):
To add lines:
{ crontab -u user -l; echo "$this"; echo "$this_too"; } | crontab -u user -
To delete lines or do more complicated edits:
crontab -u user -l | sed "$my_wonderful_sed_script" | crontab -u user -
In any case, you don't need to restart cron. It will notice the changed modification time of the cronfile.
When editing the crontab file using your regular editor, the schedule will not be updated. The system will still do the scheduled tasks as before the edit. This will drive the administrator mad.
When cron restarts, such as a reboot or a restart of the process, the current crontab files will be read and processes are scheduled as described in the current present files.
I remember sending a 'kill -HUP' or 'kill -15' to the PID of the cron process to force the process flushing the cache and reading the crontab files again.