date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,459,409,985,000
I am trying to write a cron schedule to run a job the Thursday before the second Monday in a month. So far I have this 0 0 8 ? * MON#2 But that runs on the second Monday of the month. Is there a way I can go back four days from that time to the previous Thursday? For example, for September 2016, the second Monday of ...
I don't think you can do that in cron. Maybe with 0 0 * * 4 you should run a script every thursday and in that script, you can check if it is the thursday before the second monday of the month.
cron job to run the Thursday before the second Monday in a month
1,459,409,985,000
I'm trying to record the start time of a process kicked off by an @reboot cronjob. I'm using ps -p $$ -o ltime= presently, but I've run into a catch. My machine (a Raspberry Pi) connects to the network and pulls down an NTP update after cron has started and adjusts the system clock. The time returned by lstart changes...
You can ask for the elapsed time in seconds: ps -p $$ -o etimes= This will always be accurate and comparable, regardless of what the system thinks the current time is. You can turn it into an unchanging start value by subtracting it from the current uptime (stored in seconds as the first value in /proc/uptime): echo ...
Get the process start time irrespective of NTP updates
1,459,409,985,000
In /etc/cron.hourly, there is one file: -rwxr-xr-x 1 root root 117 Mar 8 20:33 myjob myjob: 3,18,33,48 * * * * /usr/bin/python /home/me/src/myproject/src/manage.py myjobs > /home/me/log 3,18,25,27,29,31,33,35,37,48 * * * * /bin/echo "testing....." > /home/me/log /etc/crontab: # /etc/crontab: system-wide crontab #...
The scrips in /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly are meant to be run at specific times, and do not are in the classic crontab format. Or put it simply, they are scripts, not files in the crontab format. In the case of /etc/cron.hourly, they are just ran every hour. you have to inser...
why /etc/cron.hourly/myjob not working?
1,459,409,985,000
I had programmed a cronjob to restart a service with an apparent memory leak weekly and got an email saying that the killproc command wasn't found. That's in /sbin/killproc and I don't want to modify the service script, even though I'd prefer it to use absolute paths so I'm opting to weasel my fix by way of cron. So, ...
Use a sub-shell to limit scope: 0 0 * * 0 (export PATH=$PATH:/sbin; /etc/init.d/tic_minus restart)
How to set the path for one cron command
1,459,409,985,000
It's possible to set the cron job tool in my website cpanel 'VPS Hosting' to execute php file every 30 second I am using it to execute php file once at a minute *,*,*,*,* but I need to set it to run twice in minute I have tried 1/2,*,*,*,* but it's not working.
Why don't you run a shell script which runs your command, like: #!/bin/tcsh -f start: mycommand >> /tmp/output sleep 30 goto start As someone else said, cron has a granularity of 1 minute.
Run A Cron Job Task Every 30 Seconds [duplicate]
1,459,409,985,000
I have a task which I wanted it to run on every hour 56 minutes not sure which I should do below and what does "*/number" means. An example :- 12:56PM, 01:56PM, 02:56PM ... Use this ? */56 * * * * /usr/bin/python3 /home/asd/asd.py Or 56 * * * * /usr/bin/python3 /home/asd/asd.py
Using just 56 on the first field you are telling cron you want to run the script at minute 56; while setting "*/56" on the first field you are telling crontab to run the script every 56 minutes. If You want the script to run at 12:56PM, 01:56PM, 02:56PM ...; then you use 56 56 * * * * /usr/bin/python3 /home/asd/asd....
Cronjob schedule
1,459,409,985,000
I am running my runnable jar in linux machine (machineA) as shown below. In the runnable Jar, I have a java program which sends email to me every 15 mniutes. /usr/lib/jvm/java-1.7.0-openjdk-amd64/bin/java -jar abc.jar config.properties & As soon as I start my abc.jar like above, it will be running in the background a...
Get rid of the &. That makes it fork into the background, Upstart thinks the process died, then spawns a new one. Just have the exec line without the ampersand.
How to restart my java program automatically if it gets killed?
1,459,409,985,000
After editing /etc/cron.d/anacron and saving the file, are the changes immediately acknowledged by cron? Or do I need to run a command to tell cron to reload /etc/cron.d/anacron?
They work immediately after saving
Edited /etc/cron.d/anacron, changes are immediately in effect?
1,459,409,985,000
It surely going to sound like a silly question but i wanted to have a confirm about that crontab time 13 * * * * does it really mean to launch at the 13th minute of every hr of every day of every week and so on? Thx in advance
I can recommend CronSandbox to try it out, better to be safe than sorry. The output there confirms you're right as well.
cronjob time 13 * * * *
1,459,409,985,000
I'm trying to learn a little about cron. I edited crontab -e to have this line: */10 * * * * /usr/bin/touch /home/dkb/Desktop/test.txt It works and I see test.txt changing its "Date Modified" value every ten min in Thunar and there are corresponding entries in /var/log/syslog: Mar 13 10:50:01 dkb-lappy CRON[3...
crontab treats % specially. You need to escape it with a backslash. From man 5 crontab: Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input. Thus, to get date to work pro...
Using "crontab -e" [duplicate]
1,459,409,985,000
Cron: * */6 * * * /path/to/command I want this cron to run once in every 6 hour. Whats wrong with the above cron definition, and why?
You have to specify a minute value in the first column. The star there makes it run on each minute value. 10 */6 * * * /path/to/command will make it run 10 minutes past the hour, every six hours (on all days). From man 5 crontab: A field may be an asterisk (*), which always stands for 'first-last'. Thi...
When will this cron run
1,459,409,985,000
My cron and scripting skills are very poor, but I need to run a job every 5 minutes by user 'cpc'. So I created a script and left it at /root. My crontab -e entry about it is: 0-59/5 * * * * /root/bi-kettle.sh And this script (bi-kettle.sh) is: #!/bin/bash su cpc cd /home/cpc/data-integration /bin/bash kitchen.sh -re...
That su is why it fails, that launches an interactive shell. Why not add it to the crontab of the cpc user instead? crontab -e -u cpc
how do I run a cron job with a specific user?
1,459,409,985,000
I have some repos which are both in SVN and Git. My username is guyfawkes, and in my home directory I have folder www which contains all my repos. In this directory I also have file update.sh: [guyfawkes@guyfawkes-desktop ~/www]$ cat update.sh cd /home/guyfawkes/www cd crm echo "upd crm" svn up echo "update crm comple...
The problem is you are trying to update from github which requires an ssh key. Either create a dedicated ssh key without a password on your server and add it to your github account or use the http-readonly uri to update your repository: git pull --mirror https://github.com/account/repository.git
Crontab with SVN and Git
1,459,409,985,000
I'm stuck at the first hurdle! I want to run a couple of commands from a bash script. First something like this to rsync some directories: rsync -e ssh -az [email protected]:/home /location/of/local/folder Then something like this to tar and copy the files somewhere else: cd /location/of/local/folder tar zcf /var/bac...
Commands in a shell script are executed sequentially. If your first command is rsync, the next command will not execute until rsync completes. What you want to be sure of is that rsync finishes successfully before continuing to the next command. This is not the most elegant solution, but the easiest to implement. rsy...
Trying to create a cron to Rsync then tar the folder
1,459,409,985,000
I tried to run the rtcwake as root and it's working: root@ywt01-15Z90N-V-AR53C2:~# rtcwake -m mem -s 90 ↑ This command is working. But When I tried to run the rtcwake within crontab, it's not working: open crontab: root@ywt01-15Z90N-V-AR53C2:~# crontab -e edit crontab: 01 22 * * * /usr/sbin/rtcwake -m mem -s 90 ...
Don't know how to fix your rtcwake script – there's multiple things that feel a bit anachronistic about that :) Instead, systemd (as your Ubuntu 20.04 is based on!) makes it simple to have a timer task for which the system is woken up automatically. Something like https://joeyh.name/blog/entry/a_programmable_alarm_clo...
How to run the `rtcwake` within `crontab`?
1,459,409,985,000
So I was making a script that monitors my app usage. It does so by running a cronjob every minute, and cronjob in question checks which window is focused on and increments its counter by 1. Other parts of code are insignificant, this is important part: focused=$(xdotool getwindowfocus) pid=$(xdotool getwindowpid $foc...
It sounds like you do not mention DISPLAY environment variable at all. With xdotool, you'd be using X11, so the variable DISPLAY should match the DISPLAY variable from when you run this in a terminal in your graphical session: echo $DISPLAY edit: adding Quasimodo's comment here in the answer: Try export DISPLAY=:0 in...
xdotool returning different output when executed from crontab [duplicate]
1,459,409,985,000
I've got an installer/updater script that's meant for IRIX/Linux/macOS/FreeBSD and I would like to extend its compatibility to Solaris. I've already fixed a few parts that weren't POSIX compliant, except for the crontab which is generated like this: printf '%s\n' [email protected] '*/15 * * * * /path/cmd' | crontab - ...
Note that MAILTO is no good for a software installer even where it's supported, because it's a global setting: it would apply to all the entries in the crontab, not just to the one added by your software. If you want your software to send emails to a different address, you need to handle that in your own code. And tha...
POSIX (or portable) way to forward emails from crontab
1,459,409,985,000
My backup script works fine when executed manually; but nothing runs from crontab. I am running Fedora 35 Workstation. The crontab editor works: $ crontab -e The cron daemon is not running. Each of these commands has no output: $ pgrep cron $ pgrep crond $ pidof cron $ pidof crond My attempts to start cron: $ where...
Cron executed my backup script after using the crond location posted by ajgringo619: $ ls -l /usr/sbin/crond -rwxr-xr-x. 1 root root 74448 Jul 21 15:05 /usr/sbin/crond $ sudo /usr/sbin/crond start $ pgrep cron 121692
cron.service file not found
1,459,409,985,000
I'm trying to create a cron job that checks the status of certain worker machines and triggers a webhook: It works, but I'm not sure that this is the best approach: for i in $(oc get nodes | awk 'FNR>1 {print $2}');do if [[ $i != 'Ready' ]];then <TRIGGER_WEBHOOK>;fi;done Output of oc get nodes # oc get nodes NAME ...
The one thing I can see that I might change is removing the if: for i in $(oc get nodes | awk 'FNR > 1 && $2 != "Ready" { print $2 }'); do <TRIGGER API> done
Pipe for loop with awk and if
1,459,409,985,000
I have a weather station that sends data to a Raspberry PI, in which runs a linux server that takes that data and stores it. Everythings works fine except for one little thing. Raspberry is connected to the weather station indoor display, via usb cable. The display is set to reproduce sounds whenever it powers up. So ...
From the log message, we see it's run via cron (and not e.g. a systemd timer), and the command is exactly sudo reboot. Most system-provided cron jobs would be in files within /etc/cron.d/, so that's a place to look. Also there can be stuff in the root user's personal crontab too. The per-user crontabs should be viewed...
Why is Linux rebooting everyday at the same time?
1,459,409,985,000
I have the following cron job in /etc/cron.d/backup: */1 * * * * backupbot /home/backupbot/bin/backup-script.sh Basically, I want the backup-script.sh to run every minute (and the user backupbot should be executing the job). The /home/backupbot/bin/backup-script.sh file is owned by backupbot (and he has "x" permissio...
According to comments, the script is only executable by the owner. I.e., it is not readable. This stops the owner from executing the script. Example: $ chmod 500 script $ ls -l script -r-x------ 1 myself myself 24 Apr 14 09:21 script $ ./script hello $ chmod 100 script $ ls -l script ---x------ 1 myself myself 24 A...
Not sure if cron job is run
1,459,409,985,000
The command below works nicely and puts "Hello from Docker." to out.txt docker run -it --rm ubuntu echo "Hello from Docker." >> /home/ubuntu/out.txt`` Then when I open "sudo crontab -e" and put their line below, I am getting empty out.txt * * * * * docker run -it --rm ubuntu echo "Hello from Docker." >> /home/ubuntu...
Try without options -it these are for interactive terminal. But you are using in a script with no terminal, no interaction.
Docker run is not working as cron command
1,596,117,343,000
DEMONSTRATION (OR STRAIGHT TO THE REAL QUESTION SECTION) I have a lynis script that I use to scan my server. This script is not important to demonstrate but here is the script anyway: https://gitlab.com/sofibox/maxicron/-/blob/master/usr/local/maxicron/lynis/maxinis This script runs perfectly and doesn't output any er...
The reason grep isn't working is that the messages are going to stderr, not stdout, so grep is never seeing them. That's why you're getting an email even after sending stdout to /dev/null. You can filter stderr like this: somecommand > /dev/null 2>( grep -v 'unwanted error' 1>&2 )
How to suppress a specific warning sent by cron daemon to email?
1,596,117,343,000
i want run a CronJob for reboot the server once or twice at month. I do: crontab -e than: 51 9 5 * * /usr/sbin/reboot This should reboot at 5 day of the month at 9:51, it works the server is reboot but after 30 seconds the reboot continue generating an infinite loop. Why this happen and how to fix? The only way i ha...
The issue was caused by the click not synchronized. I resolved by doing a cron that run before the reboot with the following command: /sbin/hwclock --systohc >/dev/null 2>&1 than /usr/sbin/shutdown -r +5 >/dev/null 2>&1 works. Without the command mentioned to sync clock the issue persist.
Why crontab on Centos 7.8 for reboot the server once generate e reboot loop?
1,596,117,343,000
I have a simple backup script with this line to come up with a name for the backup: backup=$(/bin/date +'%Y-%m-%d_%H:%M_%S')_$(hostname).gz It works great when I run it under the root user. Unfortunately when I set it to run as a cronjob, the $(hostname) part is always empty and I don't get the hostname. Why isn't...
hostname doesn't seem to be in the PATH in your script. Either put /bin/hostname there, like you did for date, or set PATH to include /bin (inside the script or in the crontab).
$(hostname) doesn't work in cronjob [duplicate]
1,596,117,343,000
I have setup a cron job from cpanel to email me daily so I know the site files have been backed up. However, it emails the entire file paths and the whole job. Snippet of the email output I receive; tar: Removing leading `/' from member names /home/user/public_html/ /home/user/public_html/test/ /home/user/public_html...
You can remove the -v (verbose) option, and instead use the tar command's exit status to determine what message to send. Ex. at its simplest, tar -cpzf /home/user/backups/backup_files.tar.gz /home/user/public_html && echo "Files successfully backed up at $(date)" or (slightly more nuanced) tar -cpzf /home/user/backup...
How to limit the email output from a Cron Job
1,596,117,343,000
I've been reading the recent blogpost "Winding down my Debian involvement" by Michael Stapelberg. Sad details aside, it's been mentioned that within Debian infrastructure batch jobs run four times a day at XX:52 UTC: When you want to make a package available in Debian, you upload GPG-signed files via anonymous FTP. T...
It is not random, and it is something that a system administrator should think about. Notice that your cron.hourly, your cron.daily, your cron.weekly, and your cron.monthly are all run at different times. These times have varied over the years, and have been moved back and forth, because these jobs interact with one ...
Starting batch jobs at exact time slightly before the new hour starts
1,596,117,343,000
I have a crontab root file that looks like this: lab-1:/var/www/cdd# crontab -l # do daily/weekly/monthly maintenance # min hour day month weekday command * * * * * /etc/scripts/script1 */15 * * * * /etc/scripts/script2 0 * * * ...
A common mistake when writing scripts that will be executed later by cron, is that you assume the script will have exactly the same environment that you have when you are logged in and you are developing it. It hasn't! Write a script4 which contains the following line OFILE=/tmp/crons.environment (/usr/bin/whoami /usr...
How to troubleshoot failing cron job
1,596,117,343,000
I'm trying to get a script to run according to a crontab entry. The script I have works fine in the terminal but will not run automatically as per the cron entry. The script is simply to create an empty file in the /testexport1 directory once an hour. I used crontab -e to edit the crontab, which looks like this: 30 ...
The crontab is not running the script because /bin/bash/ can most likely not be found. This should read /bin/bash instead (note the lack of / at the end), or whatever the correct path is to bash on your system. Also make sure that all utilities that you are using in the script are actually found in the $PATH that you ...
Getting cron to run a script
1,596,117,343,000
I am really struggling to get to the bottom of this one. For some reason cron cannot see a file system I mounted manually. This is a USB drive formatted to ext4 mounted to /backup. For completeness I mounted it while logged into SSH, not directly at a terminal. If I compare typing mount | sort at the commandline (ov...
This sounds like the daemons are running in different mount namespaces, so changes you make in your SSH session aren’t visible in cron or at jobs. Look at mountinfo and ns/mnt inside the various deamons’ /proc/${pid} directories to check which namespaces they’re using and what they can inherit.
What can cause different processes to see different mount points?
1,596,117,343,000
I have setup 3 crontab jobs to execute my simple ruby scripts periodically every minute, 5 minutes and hour. They execute, however they do not do anything. I have only one user on the machine (root) and I have setup the crontab by executing the command crontab -e. crontab -l lists my current crontab jobs: 5 * * * * ...
You have not set these jobs to run every minute, every 5 minutes, and every hour. All three are set to run once per hour, at :01 past the hour, :05 past the hour, and :00 past the hour. Instead you might try something like * * * * * echo 'run every minute' */5 * * * * echo 'run every 5 minutes' 0,5,10,15,20,25,3...
Cron jobs not working as expected
1,596,117,343,000
I have two bash scripts. One runs as root, and it calls another one as user "parallels" /root/cronrun.sh #! /bin/bash PARR="thisparameter" echo "Starting at `date`" >> /root/rlog.log runuser -l parallels -c "/home/parallels/testscript/newscript.sh $PARR" echo "Finishing at `date`" >> /root/rlog.log /home/parallels/...
cron runs with a specific PATH, as seen in the upstream Debian source code: #ifndef _PATH_DEFPATH # define _PATH_DEFPATH "/usr/bin:/bin" #endif Referenced here: #if defined(POSIX) setenv("PATH", _PATH_DEFPATH, 1); #endif and since runuser lives in /sbin, you'll need to use the full path to it, or set PATH in you...
Cron shell ignores runuser command - why?
1,596,117,343,000
I've got this strange behaviour Empty string parsing ntpq command result, but let me resume and refocus the problem: I'm executing a java program launched using a shell script that goes like this: #!/bin/bash export PATH=.:$PATH java -jar myJar.jar & Inside my java code I execute this piped command ntpq -c peers | a...
I originally posted a similar question in StackOverflow, thinking that the problem may be related with the java programming but it wasn't. Finally we found what was happening. My java program is launched with a shell script. When we execute the script manually, ntpq command is found and invoked successfully. The probl...
/bin/sh: ntpq: command not found
1,596,117,343,000
Running Ubuntu 16.04 I have added the following to /etc/crontab: * * * * * root wget https://www.exmaple.org/bus/ >/dev/null 2>&1 The cron job runs properly, but the result is written as a file to /root/ rather than being discarded as expected.
>/dev/null discards the standard output of the command. There is none in your example. 2>&1 causes the standard error of the command to be discarded. In your example, this contains status and error information displayed by wget. If the URL is valid (as in, if the server returns some content for the page), wget saves t...
Why might >/dev/null 2>&1 not work?
1,596,117,343,000
How to execute a different command/script (Task-B) in a parallel mode, while the primary task command/script (Task-A) is exceeding the defined time window/period; which is mentioned in the crontab ? @ Production environment, not having gnome-terminal.
As l0b0 mentioned in his answer, the crontab file only specifies the start time of jobs. It doesn't care if the job takes hours to run and will happily start it again when the next start time arrives, even if the previous incarnation of the job is still running. From your description, it sounds like you want task B to...
Execution of Parallel Script from a single Cron Job
1,596,117,343,000
I have a bunch of munin nodes going and every five minutes they produce this message in /etc/syslog: CRON[5779]: (root) CMD (if [ -x /etc/munin/plugins/apt_all ]; then /etc/munin/plugins/apt_all update 7200 12 >/dev/null; elif [ -x /etc/munin/plugins/apt ]; then /etc/munin/plugins/apt update 7200 12 >/dev/null; fi) T...
There are two sets of cron jobs for a user: the user's crontab (edited with crontab -e), and the system crontab (/etc/crontab). The system crontab allows the system administrator to execute jobs as any user — typically root or a system account. It's unusual to have a user crontab on a system account, because the syste...
Where does this munin cron job come from?
1,596,117,343,000
I want to be able to run my script, say, 2 or 3 times per day -- 24 hours -- but at a different time each time. What would you recommend a simple and reliable solution?
To run the script 2 times per day: 0 0,12 * * * sleep $(( $$ \% 21600 )); /path/to/script.sh This will start the job at noon and midnight, then sleep for up to 6 hours (half of the 12-hour interval) before starting the script. To run the script 3 times per day: 0 0,8,16 * * * sleep $(( $$ \% 14400 )); /path/to/script...
Running a script via cron at a random time, but a certain number of times per day [closed]
1,596,117,343,000
I have some cron tasks unique to root. One of these has a reboot command in the end. Say I SSH with my work user and while doing some task with it, the reboot-requiring root task will run in the background: Will the root reboot log my other work user of the SSH? If I would have to bet, I would bet that it won't take m...
If you have a cron job that has a reboot command in it, the whole system will get rebooted (as @AlexP said), no user sessions (local or remote) or processes will stay active. As an aside, you might want to consider why you have a reboot task in your cron job; is there a service or process you could restart rather than...
root cron task that requires reboot will get me out of the system if I use another user?
1,596,117,343,000
Per the attached screenshot of htop, about five minutes after I log in to Mint Linux 17.3 it automatically starts a background process for /usr/bin/find, USER nobody, at which point that process consumes 84-percent to 100-percent of the (virtual machine's) CPU. (At that point I can tell without using htop that the pro...
This find process is running as part of the updatedb task, which updates the database for locate, a command to locate a file given (part of) its name. It is triggered by anacron, a service that runs scheduled tasks when the computer is turned on. Anacron complements cron, which runs tasks at a predefined time: the upd...
Controlling automatically started /usr/bin/find process
1,596,117,343,000
I have a cron job supposed to trigger a shell script daily at 2 AM. 0 2 * * * /root/bin/script.sh However it does not work at all. What am I missing? More details: The script runs fine without cron scheduling when run manually and does what it is supposed to do. Root user is running the cron job. The cron job was sch...
My guess is that your script isn't being understood properly by the shell, because it doesn't have any proper shebang. Try using crontab -e with this instead: 0 2 * * * bash /root/bin/script.sh > /tmp/crontest.log 2>&1 By invoking the script directly using bash, the script should run fine now. Any output should end u...
Daily cron job does not seem to work
1,596,117,343,000
Is the following crontab possible? 0 4 * * * /sbin/sudo shutdown -r now I want to run a single command, sudo shutdown -r now, from a crontab without having to put it in a bash script.
Normally, sudo will be useless in a crontab. The cron program runs the commands in a restricted environment (most notably a very limited PATH and no controlling tty). While you could probably get this to work by installing severe security holes, the right way to achieve what you probably want is to put the command s...
Inline Crontab Commands?
1,596,117,343,000
I tried posting this on Stackexchange but I think I may have more chance of a correct answer here as its very linux specific. I have an sh script which updates data in a csv, then runs a perl script ($match) from within the sh script that matches data between two csv files and populates the file $matches with the mat...
Your perl script has open CSV2, "<csv2" or die; ... open CSV1, "<csv1" or die; Where are those files located? cron's current directory is the home directory of the user. If the files are in the "newitems" directory, you have to cd there first. Make sure you're not making any other assumptions about the environment in...
sh script containing perl element does not produce same output via crontab as manual execution
1,596,117,343,000
I need to a crontab execute each 12 hours, so I have the following: 0 */12 * * * . /X.sh then Linux is installing new crontab. after that, I am waiting for 2 hours and still the cron job didn't start?! When has it to start the job?
The crontab entry you've written is equivalent to 0 0-23/12 * * * . /X.sh This requests execution on the hour between midnight and 11pm, using 12-hour steps — so cron will run the job every day at midnight and noon.
when the cron job start after installing new crontab?
1,596,117,343,000
Trying to add text on the line before that it find the match (updateKey.sh) in this case, but won't get it to work. Here is my crontab file that the script adds the line to 0 06,18 * * * /home/server/scripts/CCgenerator.sh 0 05 * * * /home/server/scripts/updateKey.sh The first line "CCgenerator.sh" is sometimes delet...
For cron edit purpose l0b0 answer is the best way, to fix your script you have to: escape dots and asterisk in your search key (updateKey) use alternative separator in sed (I choose %) double quotes around sed expression (you want your bash variables resolved) #!/bin/bash CCgenerator="0 06,18 * * * /home/server/sc...
add text on line before match
1,596,117,343,000
I typed the following into crontab -e 0 0 * * * bitcoind -datadir=/home/pi/bitcoinData -daemon 0 6 * * * bitcoin-cli -datadir=/home/pi/bitcoinData stop I expect this to run bitcoind -datadir=/home/pi/bitcoinData -daemon at 12am every day and then run bitcoin-cli -datadir=/home/pi/bitcoinData stop at 6am every day. Bu...
Solution to the problem is to modify the entries in cron with the absolute path names. Added cron command logging capability as the machine doesn't have an MTA to send failure notifications, as follows: 0 0 * * * /usr/local/bin/bitcoind -datadir=/home/pi/bitcoinData -daemon >> ~/bitcoinData/bitcoin-cron.log 2>&1 0 6 *...
Two cronjobs not working (one to start a process, one to stop a process)
1,596,117,343,000
I set cron to run script every day using env EDITOR=nano crontab -e where I wrote something like this @daily path/to/sript.script Now I want to use anacron to be sure that script is going to be run when I log in if I was logged off at the time when it was scheduled. But I am not sure where to specify that. I tried som...
I found that anacron is not an installed utility in OS X. Scheduled tasks are handled by launchd, cron has been depreciated in OS X.
Setting anacron on mac
1,596,117,343,000
We have an app deployed in a server, which, under some scenarios, generates some logs in the below format. process_name.hostname.common_text.log.{error/info/warning}.date.time Now, due to this format, there isn't one log, but several such logs all with same process_name.hostname.common_text.{error/info/warning} part...
If you use -1 instead of -l for ls, you get only the filenames and can pass them directly to rm. I would use something like this: rm $(ls -1tr process_name.hostname.common_text.log.error* | head -n -1) \ $(ls -1tr process_name.hostname.common_text.log.info* | head -n -1) \ $(ls -1tr process_name.hostname.common_text.l...
handle large number of same log using cron or logrotate
1,596,117,343,000
My question comes from an observation that I made while seeing an every minute cronjob running like that: 12:00:15 (cron started) 12:01:20 (cron started) 12:02:02 (cron started) . . . As it seems the cron doesn't run every minute (every 60 seconds). That cron actually runs a php script that does a mysql query that se...
What you observe doesn't surprise me at all, cron is not precise to the second. You can trust* it to run the job within the minute you programmed it to run, but you shouldn't really rely on more precision. If you need your job to start at a precise moment, you should start it earlier and wait inside the script for tha...
When a cronjob really starts?
1,596,117,343,000
Is it possible for a Cron Bash Script to echo to the current session terminal instead of /var/spool/mail/root I have a script which writes errors to a log file but any supplemental/unimportant info I echo out to the terminal. When I run the script in cron as root it redirects the messages to /var/spool/mail/root rathe...
You can use the write utility to send text to a specific logged-in user. command that produces output | write root The documentation further explains: To write to a user who is logged in more than once, the terminal argument can be used to indicate which terminal to write to; otherwise, the recipient's terminal is ...
Cron Bash Script - echo to current terminal instead of /var/spool/mail/root
1,596,117,343,000
The job works if set like this: */1 * * * * /usr/bin/php /home/test/cron/test.php And if set to something like: 15 20 * * * /usr/bin/php /home/test/cron/test.php it's not working. [root@localhost mail]# uname -or 2.6.18-308.el5 GNU/Linux [root@localhost mail]# cat /etc/*elease #CentOS release 5.8 (Final) redhat-4 I...
Updating /etc/localtime for the system wide time zone setting might fix your problem. I guess KST stands for Korea Standard Time, so you might want to choose /usr/share/zoneinfo/Asia/Seoul for it. You can also run tzselect to know which file in /usr/share/zoneinfo to choose. $ sudo cp /etc/localtime /etc/localtime.o...
Cronjob is running every minute but not at a specific time
1,596,117,343,000
I need to set up a job to delete all of the regular files in the /home/admin directory on the second day of every month at 8:30 A.M. It seems like wrong command: # crontab -e 30 08 02 * /bin/find /home/admin -type f -exec /bin/rm {} ";"
You need to add 30 08 02 * * and \; # crontab -e 30 08 02 * * /bin/find /home/admin -type f -exec /bin/rm {} \; Now it will work.
How to set up cron job in Linux to delete all regular files?
1,596,117,343,000
I've got a bunch of CronJobs, and they work fine, except for one. I've looked through a lot of forums and websites, and tried a combination of things but alas nothing has worked. Rephrasing the question is: Q: The bashscript works without any problems from the terminal. But with the CronJob it does not work at all. T...
The solution that worked for me is I changed all of the paths within my two programs from relative paths ie: (./name_of_file.txt) to full paths (ie: /home/ed/directory/some_more_directory/name_of_file.txt) Was it just this, or a combination of the other things I did, I don't know - but changing the paths from relative...
BashScript works from Terminal but not from CronTab
1,596,117,343,000
I'm trying to set up a cron job in order to backup my databases daily. Here's what I wrote in my crontab file : 25 18 * * * root mysqldump -u root -p myPassWord --all-databases | gzip > /var/backup/database_`date '+%m-%d-%Y'`.sql.gz As nothing happened at 18:25, I had a look in my /var/log/syslog file (the server is...
Debian has a package for you to take care of dumping, compressing and rotating MySQL data. You can install it with the following command: $ sudo apt-get install automysqlbackup After this daily, weekly and monthly dumps will be placed in /var/lib/automysqlbackup
Databases backup with cron
1,596,117,343,000
I'm looking for a scheduler daemon like cron, but with at least seconds precision so I can use it for a radio automation app. I've heard conflicting rumors about cron's ability to handle seconds. If it is already capable of doing that then I'd be happy to hear that information as well.
You can do : * * * * * sleep 5; script.sh * * * * * sleep 10; script.sh ... * * * * * sleep 55; script.sh to run the script every 5 seconds.
High precision scheduler daemon
1,596,117,343,000
I'm trying to automatize the updates of debian system, without making upgrades. Then i'll send an e-mail to me, everytime there is an upgrade available. I've tryied to do it with cron-apt, but i really don't like how the configuration is organized, that's why i would prefer using a (cleaner) cron job that launch the s...
Don't reinvent the wheel. apt-get install apticron Apticron is a simple script which sends daily emails about pending package updates such as security updates, properly handling packages on hold both by dselect and aptitude.
automate updates with a bash script and cron
1,596,117,343,000
I need to open one (or more) browser tab periodically and I decided to use cron. The command in the shell (bash) that correctly executes this task is chromium-browser http://mysite.com. If I type it, the browser opens the site in a tab. But the same command inserted as a task in the crontable doesn't work. If I redire...
i added the following to my crontab by typing crontab -e and it worked * * * * * env DISPLAY=:0 google-chrome www.github.com My chrome browser opened www.github.com every minute. So the following should work for you. * * * * * env DISPLAY=:0 chromium-browser http://mysite.com
Cron task in graphic interface
1,596,117,343,000
I'm trying to chain some commands to periodically check/launch two processes via cron (I'm on a shared host, can't change things around). After a lot of googling around, all the things I've done don't work properly: Trying to launch them separately in two cron jobs cascades and crushes the server (maybe because the gr...
$USER is not set in most crons. Luckily ps -u without a username defaults to the present user (which is the user from which cron is running for). However your grep has quite a high chance to match the grep itself as well as the celery processes. You can clean that issue up with a sneaky grep '[c]elery'. This will matc...
Launch 2 celery processes via cron
1,596,117,343,000
I have this txt files that contains IPs, one per line of file, that I want to block using ipset. I have this bash script that essentially reads from the plain txt file and constructs an array. Then it iterates the array elements and add each one to the ipset I have created for that purpose. The problem is this: if I e...
Your shell knows where to find executables (like ipset) by looking in your PATH, which is set by your environment. cron does not share the same environment. Adding this at the top of the crontab (or your script) should tell it where to find commands as you expect: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin...
ipset not executing from crontab
1,596,117,343,000
I have a cron job: #!/bin/bash fn=db.backup.$(date +%m-%d-%y).sql mysqldump -uMyUsr -pMyPass --add-drop-table dbName> $fn find ./ -name '*.Z' -type f -mtime +7 -exec rm -f {} \; I get an error: /backup.sh: line 3: db.backup.10-24-12.sql: Permission denied db.backup.10-24-12.sql: No such file or directory find: ./con...
you should use: fn=/full/path/to/db.backup.$(date +%m-%d-%y).sql or cd /full/path/to/ before you export the database unless your cronjob looks like: * * * * * cd /full/path/to && backup.sh
Cron job - permission denied creating a file
1,333,433,627,000
I have a number of computers and each computer is starting cron jobs left and right. Those are both server computers and desktop computers. On desktop computers it would be inconvenient if a user would shutdown the computer while a cron job is running. I am thinking of mv-ing the shutdown command, and have users shutd...
The shutdown command doesn't know anything about cron jobs, but if you're on a modern system then shutdown is actually handled by systemd, and systemd knows about inhibitors, which allow you to prevent certain activities -- like system shutdown, suspend, etc -- while a command is running. You can use the systemd-inhib...
Shutdown command vs cron jobs
1,333,433,627,000
When cron runs 0 16 * * * journalctl --vacuum-time=10d I get an email with the content like Vacuuming done, freed 0B of archived journals from /var/log/journal. Vacuuming done, freed 0B of archived journals from /var/log/journal/68eb3115209f4deb876284bab504772b. Vacuuming done, freed 0B of archived journals...
Simplest thing to do is to pipe through 2>&1 | grep -v 'freed 0B' If cron runs a command that produces zero lines of output, then cron will not send an email.
suppress cron emails from cleaning systemlog if 0B were cleaned
1,333,433,627,000
I'm using linux: Distributor ID: Ubuntu Description: Ubuntu 18.04.6 LTS Release: 18.04 Codename: bionic I noticed a few weeks ago that there is a file in my home directory: dead.letter. The file is updating at the first second of every minute with the same number of log line. I have been searching for...
Found the problem: We use nfs mounts in our organization. We also use AWS. We created a new instance from an ec2 instance I was working on. The template instance had a cron job, that kept running on the new instance, and writing data to the shared directory.
What process is generating dead.letter?
1,333,433,627,000
I have two users: user1 and user2 user1 is added to /etc/cron.allow But when I run crontab with the -u option, I get : user1@hostname:~$ crontab -l -u user2 must be privileged to use - Is it possible to grant this crontab -u permissions for a user without giving him sudo rights?
You can grant sudo access to just that particular command. For example, the following rule... testuser1 ALL=(ALL) NOPASSWD: /usr/bin/crontab -l -u * Would let testuser run crontab -l -u <someuser>. E.g, these all work: [testuser1@fedora ~]$ sudo crontab -l -u testuser1 no crontab for testuser1 [testuser1@f...
Allow 'crontab -l -u' for non-root users
1,333,433,627,000
I want to run a some scheduled commands on a timed basis within a manually startedscreen session and only within that screen session, because it uses an ssh authentication tied to that session. Basically it means that after I start the screen session, I add the ssh key for the session then I start the command, so all ...
Asking around led me to supercronic which is described by its developers as a crontab-compatible job runner, designed specifically to run in containers. Although it was designed with containers in mind it works as a regular user program and can use crontab format files for scheduling and running tasks.
Is there a user-level utility which offers the features of "cron" or "at" and only within a particular session?
1,333,433,627,000
I wanted to set up an anacron task to run a backintime backup once a day (Ubuntu 20.04.3 LTS). If you schedule this using the backintime GUI, the normal crontab is being used, but for my use case this is not suitable: I usually have my computer on standby when I'm not using it, so the cronjob would just be discarded i...
Edit: The workaround below didn't work 100% of the time, so I went digging again and identified that the root cause is not anacron itself but rather its systemd configuration: Apparently systemd units can specify a kill mode that is used to clean up any spawned subprocesses once the main process is done. Anacron had t...
Anacron kills children of my task
1,333,433,627,000
After researching enough on the times when cron.daily (and weekly and 'hourly') run, I found the following command - grep run-parts /etc/crontab But the output of this command isn't very intuitive. If I want to see the corn running times in a human readable format, like the one given by the date command, what should...
You can use hcron - hcron . You can specify a crontab file and it will parse it the way you would expect. My tip would be to rename the binary after extracting the package, because the binary defaults to the name cron. Example output: ./hcron --file /var/spool/cron/root 00 15 * * *: At 03:00 PM | command-foo 0 23 * *...
Print the cron time in human readable format [duplicate]
1,333,433,627,000
I am new to linux and I am trying to automate my update/upgrade script for my raspberry pi. Right now it is set to do it every 1 minute, so I can see whether it logs what it does. Later on I will be making it so that it would run once every X time. However it does not log anything nor does it create the out.log file. ...
apt generally requires root permissions, and so you should put this in the root crontab instead of a user crontab. On RPi, you can actually get away with using sudo in a user crontab as long as the user is pi, but this may not work on many other distributions - it's not a good practice. Instead, use this: sudo crontab...
cronjob does not output message for automated apt
1,333,433,627,000
What are the differences in using crontab editing directly: vi /etc/contrab And using: crontab -e Because if you use one or the other, the commands inside the file are not the same.
The crontab command manage crontab files for USERS. These crontab are defined in /var/spool/cron/crontabs/ directory ; they are not intended to be edited directly ! The /etc/crontab is the SYSTEM crontab file, which can be edited directly.
Different Crontab - Linux Debian
1,333,433,627,000
I have small check if today is first Monday of month which is like this: ['$(date "+%u")' = "1"] && echo 'trąba' but I get the error when crontab is sending me an email that something went wrong /bin/sh: -c: line 0: unexpected EOF while looking for matching `'' /bin/sh: -c: line 1: syntax error: unexpected end of fi...
Fixed POSIX code follows: [ "$(date +%u)" -eq 1 ] && echo trąba Errors / warnings / infos were: missing spaces in [ .. ] block apostrophes instead of double quotes equal sign instead of POSIX -eq in test [ .. ] you do not have to quote anything after echo you do not have to quote numbers you do not have to quot...
Command not working in crontab [duplicate]
1,333,433,627,000
I have 3 shell scripts which I want to run in order in separate days. how can i do that with crontab? for example i have these 3 scripts: test1 test2 test3 today is Monday. script test1 is executed at 12 o'clock. tomorrow is Tuesday. script test2 is executed at 12 o'clock. Wednesday, test3. Thursday, test1. Friday, te...
The easy way is to run a script daily, and let it keep track of which script to run. something like: #!/bin/bash # find my name me="${0##*/}" # make sure the counter file exists. counter="/var/run/$me" if [[ ! -f "$counter" ]] ; then echo "1" >"$counter" fi maxcount=3 pick="$(cat "$counter")" nextpick=$(( pick + ...
how to use crontab to run scripts so that they are executed one after the other on separate days?
1,333,433,627,000
I am trying to schedule a cron, where if a month has 5 weeks and 5 wednesdays, script A.sh should run on 1st week wednesday 2nd week Wednesday, 3rd week wednesday and 4th week wednesday, where as on 5th Week Wednesday it should run b.sh. Else I am trying to schedule a cron, where if a month has 4 weeks and 4 wednesday...
Original Answer to The Original Question. You need something like this: 0 1 1-21 * * [ $(date +\%u) -eq 3 ] && "call your command/script here" This schedule 0 1 1-21 * * means run the jobs "at 01:00AM on every day-of-month from 1 through 21; now the question is why do we limited to 1-21? The answer is because in best...
How to schedule a cron for 1st 2nd and 3rd week and on specific day of week?
1,333,433,627,000
I don't fully understand man cron, and the handling of the first % symbol. Unlike most questions about % in a crontab file, I'd actually like to use % as newline. What do I need to do with the first % so it isn't interpreted as either a literal "%" symbol, or a change/redirect of stdin? I don't quite understand what i...
In the crontab, the part after the time specifications and up to the first unescaped % makes up the code to be passed to the shell (as the argument after sh and -c). What comes after that first % makes up lines to be fed to that shell via its stdin. In effect, with a crontab line such as: * * * * * shell code%line 1%l...
How to handle the first '%' in a cron command?
1,333,433,627,000
I'm trying to set an ENV variable in a crontab every so often to change the session_secret. Using both ruby and bash, I can't seem to get out of the sandboxed environments that they use. I need to set this variable to a randomly generated hex value of so many characters. Is this possible? I can't seem to change the...
Wrong conclusion - ability to change the process environment from outside the process. Let's say you run a ruby script. This starts a bash shell instance with environment vars, in which the ruby interpreter starts inheriting the current bash shell instance environment and maybe adding some interpreter specific new en...
How Set ENV Variable Using crontab for All Users?
1,333,433,627,000
I have a cron job which should run once a week to update, upgrade and autoclean apt, but it never seems to work, at least not as far as I can tell. This is apparent because running sudo apt-get upgrade (weeks after the cron job was added) shows there are packages ready to be upgraded. System info Linux squire 4.15.0-8...
I've just seen your error messages from the log run dpkg: warning: 'ldconfig' not found in PATH or not executable dpkg: warning: 'start-stop-daemon' not found in PATH or not executable dpkg: error: 2 expected programs not found in PATH or not executable and Note: root's PATH should usually contain /usr/local/sbin, /u...
Cron job doesn't run
1,333,433,627,000
I have a Python script which runs in multiple instances with different parameters, for instance: python3 proc.py -s -v -l proc_one.log python3 proc.py -c -v -l proc_two.log I usually start these in tmux sessions with a script on boot and manually check in on these, to restart if they crashed. tmux new-session -d -s p...
Make a service. Put [Unit] Description=ProcOfMine After=network-online.target [Service] ExecStart=python proc.py --args ok Restart=always [Install] WantedBy=multi-user.target in /lib/systemd/system/proc.service Also implement error handling so that the script does not crash.
Keep a Python script with parameters running, restart if crashed, in a tmux session
1,333,433,627,000
I would like to run a Python script every day if my computer is on and it has been connected to the Internet. How can I do it? My effort is 00 14 * * * python3 /home/jaakko/.config/spyder-py3/temp.py But the problem is that I don't know if my computer is on on that time and if it has an access to the Internet.
You should use anacron instead of cron. In /etc/cron.daily, create a file (I'll call it script) with these contents: #!/bin/sh while true; do for host in www.ieee.com www.stackexchange.com; do if ping -w 4 $host; then python3 /home/jaakko/.config/spyder-py3/temp.py exit 0 fi...
How can I run Python script once a day if computer is on and it has a connection to the Internet?
1,333,433,627,000
I have a script that verifies the battery level using acpi and if it's below certain threshold it should lock the machine and hibernate. The script is executed every minute using crontab The problem is that the machine gets locked but never hibernates. The script: #!/bin/sh acpi -b | awk -F'[,:%]' '{print $2, $3}' | {...
I have found a solution. Apparently the problem was in the polkit package that defines the policies for users to shutdown, reboot, suspend, hibernate, etc As I had no rule file in /etc/polkit-1/rules.d the default is not to allow users to hibernate or suspend the machine while a user is logged in (I believe the proble...
`systemctl hibernate` not executed on crontab script
1,333,433,627,000
My cron jobs have stopped working on my CentOS 7 server. The server is running WHM/cPanel. It seems like it is an issue with PAM service because in /var/log/secure I can see the following errors when the cron jobs try to run: Jun 24 10:45:01 server1 crond[22400]: pam_access(crond:account): auth could not identify pass...
I was able to solve the issue. It is related to a file called /lib/libgrubd.so. If you're experiencing this issue then check /etc/ld.so.preload. If this file contains /lib/libgrubd.so (it may be the only line in that file) then remove that line and PAM should start working again. I also removed the /lib/libgrubd.so fi...
Cron jobs have stopped working due to PAM
1,333,433,627,000
I'm working on a script for user Bob with the relevant parts shown below. Problem I'm having is if I put this cronjob under user Bob, zenity will work but shutdown wont. And if I put it under root shutdown will work but zenity won't be visible on console. #!/bin/bash eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /p...
Non-privileged users cannot shutdown a machine from command line. If you absolutely need to send shutdown as Bob, you can add him to sudoers using visudo. sudo visudo Add the following line to is: bob ALL = (root) NOPASSWD: /sbin/shutdown -h "now" Save file. Then you can su as bob and test the command: sudo /sbin/sh...
Cron Job Console Connect and Root Permissions
1,333,433,627,000
I have a python script that should be restarted automatically every time it fails. I've trying to use for this purpose cron with the following setting: */2 * * * * pgrep -f handler.py || /usr/bin/nohup /usr/bin/python3.6 /root/projects/myproject1/handler.py & Although, if I run this command directly in cli it starts ...
It's better to run the script as a systemd service or under supervisor or similar process control system. EDIT: Just to clarify the reason. You do not have to invent wheel. Both systemd and supervisor does exactly what You need.
Cron watchdog for a python script
1,333,433,627,000
Background: I want to backup some files on my laptop on a daily basis, and there are times when the laptop is shut down for several days in a row. I tried scheduling the backup as a cron job and using anacron to execute missed jobs, but was not sure about the way anacron works. If, for example, I start the laptop aft...
If you have an anacron job that runs a daily backup, and your system is down for three days, anacron will run the job once when the system comes online on the fourth day. To elaborate, anacron allows you to specify commands to be repeated periodically with a frequency specified in days. When anacron is invoked (which ...
How to cancel anacron jobs delayed for a certain length of time?
1,333,433,627,000
I have a server (Ubuntu 18.04) that is supposed to execute a Django management command at a certain interval. (every day at 16:30) I have setup jobs like this before, using cron but for some reason the server fails to execute my cronjob. The line that I am trying to run is as follows, its using the executable of a pyt...
In the terminal use: echo $PATH When cron is running it doesn't know all your paths that allows your python script work in the terminal. The solution is to create a bash script that calls the python script. Before doing so however it executes: PATH="new-paths:$PATH"
Cronjob not executing, but command works
1,333,433,627,000
As all know the content of /tmp should be deleted after some time. In my case we have machines ( redhat version 7.2 ) that are configured as following. As we can see the service that is triggered to clean up /tmp will be activated every 24H ( 1d ). systemd-tmpfiles-clean.timer from my machine: more /lib/systemd/syste...
This combination will certainly work. However, instead of removing all in /tmp every hour, you're probably better of by deleting the resource files and directories only, e.g. R /tmp/*_resources Keep in mind that your changes on the systemd and tmpfiles configuration should not be done in /usr or /lib. Instead, place ...
how to manage cleaning of /tmp better on hadoop machines
1,333,433,627,000
I'm doing a cronjob task which creates a daily database backup. To desctinct the daily files, I name them as follows: dump- (the current date). The backup operation went well, but the date is not interpreted as it should be (dump-$(date '+%Y-%m-%d')) instead of dump-14-12-2018. #filename=dump-$(date '+%Y-%m-%d') #*/3...
It's hard to tell what your problem is, since you show us a file that's 80% commented out, but it looks like you are treating the crontab file as if it were a multi-line shell script.  It's not; each line is a self-contained, independent entity.  So you cannot assign a value to a variable on one line and use it on ano...
Can't display the date correctly in a file generated by a cronjob [duplicate]
1,333,433,627,000
Yesterday I've configured rsnapshot on a debian 9 machine, but the cron's I've set for the backups in /etc/cron.d/rsnapshot are not being executed. Also, after I save & close the /etc/cron.d/rsnapshot it doesn't say it installed the new crontab. How can I find out why it's not being executed? I've already done some se...
You miss one space in the cron record. I should be like this: 0 */4 * * * root /usr/bin/rsnapshot hourly
Cron.d not running (rsnapshot)
1,333,433,627,000
I have the following script: #!/bin/bash /usr/bin/echo q | /usr/bin/htop -C | /usr/bin/aha --line-fix | /usr/bin/html2text -width 999 | /usr/bin/grep -v "F1Help\|xml version=" > htop.txt It just captures the htop output. It works fine if I run the script via command line but then if I run it via crontab as root: 15 1...
You should use grep with the --line-buffered flag, otherwise grep exits after the first match. I don't have a full qualified explanation for this, but that's what made my script work in a similar case. Found this answer to line-buffer for grep. Installing a cronjob as root user with htop can result in a error messag...
Running Script via Crontab With Different Result?
1,333,433,627,000
I need to start the icecast2 service on startup. To to make it run on boot, I added to crontab (root) the following line: @reboot service icecast2 start >/home/pi/logs/icecast2.log 2>&1 after restart, the service doesn't run and I get this error: /bin/sh: 1: service: not found So I followed this answer on a similar...
You don't need to use cron to get a service to start a boot. All you need is this: systemctl enable icecast2 That will start it on boot every time.
Service command not found cron
1,536,240,873,000
I got stuck with this cronjob that just won't work. I left it for a day to troubleshoot it again with some fresh idea's but still no luck. I tried to find my answer on this great post, but not everything is clear to me and at the end it still refuses to work. And to make it all worse, there are no logs, no errors to ...
Things to check in this order: Does your script run non-interactively from command line with the exact owner set? sudo -H -u user -- command Is the crontab entry syntactically correct? Note that the systemwide crontab has a further column. Restart instead of reload the cron service, then you should get an appropriat...
Crontab not working or script error?
1,536,240,873,000
I have a shellscript which can be successfully executed in UNIX with command sh Shell_script.sh; but I want it to run automatically. So I just configured a cronjob to run the script using crontab -e. The cronjob added is below: 0 7-23 * * * * /home/folder1/folder2/Shell_script.sh > /dev/null 2>&1 I want it to be exec...
You have extra * in your cron line which is interpreting as Username. Once you delete it it will be fine executed. also consider if your Shell_script.sh is not executable, you need run with sh (if it's written in sh) or bash if it's bash written. 0 7-23 * * * bash /home/folder1/folder2/Shell_script.sh > /dev/null 2>&...
What can be reason for getting "execute permission denied" in cronjob in UNIX?
1,536,240,873,000
Ultimately I want to detect a new backup file being dropped into a directory and then move that new file to another location for other operations. This needs to work when there is nobody logged into the server and the script I use to start the operation will be triggered by a crontab entry. I tried using 'inotifywait'...
All you need is incron. Install incron package first if you have Ubuntu/Debian: sudo apt install incron or use the command for Red Hat/Fedora: sudo yum install incron Open file /etc/incron.allow in your favorite text editor - let it be vim: vim /etc/incron.allow and add new line with your user name (assume it's bob...
How can I use 'stat' to detect a new file and then move it to a different directory?
1,536,240,873,000
I have below entries in crontab -e , 0 16 * * * /opt/nginxstack/Dropbox-Uploader/DatabaseDumper.sh > /var/log/cron.log 2>&1 19 20 * * * /opt/nginxstack/Dropbox-Uploader/upload_dump_dropbox.sh > var/log/cron.log 2>&1 The first shell script works fine while the second doesn't get executed. I could not find anything in ...
When a redirection fails on the command line, the associated command is not executed. Example: $ echo 'hello' >nonexistent/path /bin/sh: cannot create nonexistent/path: No such file or directory (echo never gets to execute) Your second cron job redirects to a relative pathname, var/log/cron.log. If that pathname is ...
shell script in cron not working
1,536,240,873,000
I have 2 programs, both writing to the same file (/tmp/outfile). Started by cron at the same time. Basically this is what is happening: echo -n "1111111111" >> /tmp/outfile And at the same time: echo -n "2222222222" >> /tmp/outfile The output file says "11111222222222211111". This is an example, I am talking about h...
There are two immediately obvious ways to solve this: Serialize the tasks. Instead of scheduling the two tasks at the same time, schedule a script that runs the tasks one after the other. Use a advisory locking scheme to lock the writing operation of the tasks in such a way that only one task can write at a time. Se...
Multiple >> redirects to same file by 2 scripts, mid-sentence breaking
1,536,240,873,000
I use Ubuntu 16.04 with Bash and I've created this extensionless, shebangless file /etc/cron.daily/cron_daily: for dir in "$drt"/*/; do if pushd "$dir"; then wp plugin update --all --allow-root wp core update --allow-root wp language core update --allow-root wp theme update --all --allow-root popd fi done "$rse" The ...
Looking at the other scripts in the same location on an Ubuntu machine I have access to, it is clear that these scripts should be proper shell scripts. They should be executable and have a #!-line pointing to the correct interpreter. Since you expect that the variable drt is set to something, you should check that it...
Basic usage of /etc/cron/ (d): correct pattern for /etc/cron (daily/weekly/monthly)
1,536,240,873,000
I have an Intel NUC with Ubuntu installed. It runs a Minecraft server. I wanted a simple backup system for the server, and through some Googling I found that I can do so using cron and tar. However, I seem to be unable to make cron do anything at all. I made a simple test script for cron to run. #!/bin/bash cd ~/minec...
I am not sure if this answers your question, but I would suggest you to replace this line: cd ~/minecraft/Backups With this: cd /home/ben/minecraft/Backups Make sure your script has execution permissions: chmod +x /home/ben/minecraft/Backups/Test.sh Check if cron is installed and running: /etc/init.d/cron status I...
Having trouble with cron
1,536,240,873,000
I have crontabs set up to download data published on a webpage and save it locally every x seconds: * * * * * sleep 0; wget -O /home/lab/Documents/watchdog.xml 'IP-address' and this works! I actually want to save the file somewhere else, so if I try: * * * * * sleep 0; wget -O /var/cache/watchdog.xml 'IP-address' i...
User crontabs (that you edit by running crontab -e) run as your user — so they use your user's permissions. So you need to make the file writable as your user; most likely sudo chown "$USER" /var/cache/watchdog.xml would do that, if the file already exists. (If not, sudo touch /var/cache/watchdog.xml will create an em...
Crontabs does not write to a location (permissions?)
1,536,240,873,000
For a couple of years now I've been "scraping," using lynx -dump, content from a web page containing non-latin characters. I save the page content to a file, which I then modify via the agency of sed, and send that in the body of an e-mail--all this happening in a script I created. But I'm finding, after switching dis...
lynx uses the current locales to determine the charset it can use for showing pages. This information is probably not available from cron however, so you need to do something like this: lynx -display_charset=UTF-8 -dump http://example.com/some/page.html (of course, use the charset on your system if different from UT...
Different output from lynx -dump when run as cron job
1,536,240,873,000
Normally, a cron job's stdout and stderr are e-mailed to me (as per the MAILTO setting in crontab) when the job finishes. What if my job starts another job with fork/exec (or just plain exec) or with system("foo &")? What happens with the stdout/stderr of the child job? Will I get it via email? An ideal outcome woul...
A child process inherits its stdin, stdout, and stderr from its parent. Fork and exec are common in cron jobs (consider that every command you run in a shell script involves a fork/exec). The output will generally go to the same cron email. Having it go to a separate mail is easy enough: just pipe its stdout/stderr to...
A cron job forks/exec()s before terminating. What happens to the stdout of the child?
1,536,240,873,000
I have gone through many answers as to how to add a crontab through terminal through one liners and came across only one single option everywhere which is {crontab -l; echo "1 * * * * /usr/bin/firefox" } | crontab - Running which all I am receiving is > That's it. A promt for me to type something. and second optio...
Most likely your second attempt is correct, but your expectation is wrong. Let's look at it in parts: crontab -l lists all existing entries for the current user's crontab. The echo "1 * * * * /usr/bin/firefox" just prints that line again. These two commands are then grouped together in a subshell and the common outp...
Crontab addition not working
1,536,240,873,000
I'm on FreeBSD11. I have a shell script code as cron job that check the zfs pool status and save it in a sqlite database. when I run it from terminal, it work properly but in crontab it does't work. The crontab: # SHELL=/bin/sh PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/etc/myjob/pool # #minute hour mday ...
Specify the full path of sqlite in your script.
shell script cron job not working
1,536,240,873,000
Okay so say I have a java program compiled as a jar file. I want to run four instances of this cron job to execute this jar file every Monday-Friday local time from 8am to 5pm, but at intervals of 30 mins, 1 hour, 4 hours, and 8 hours, respectively. How would I accomplish this? */30 8-17 * * 1-5 java -jar queryTickets...
# Every 30th minute of every hour from 0800 to 1700 on weekdays: */30 8-17 * * *5 <<command>> # Hourly, weekdays 0 * * * 1-5 <<command>> # Every four hours, weekdays 0 */4 * * 1-5 <<command>> # Every eight hours, weekdays 0 */8 * * 1-5 <<command>> As for the command to run, if your jar file doesn't care about or ...
Cron job to execute jar file weekdays local time 8am-5pm, no weekends