Skip to main content
56 votes
Accepted

Cron runs only once instead every minute

The script does run every minute but > truncates the file each time. If the file does not exist, it shall be created; otherwise, it shall be truncated to be an empty file after being opened. (...
29 votes

Run a cron job on the first Monday of every month?

I have a computer with locale on Spanish, so, this approach isn't working for me because mon changes to lun Other languages would fail as well, so, I did a slight variation on the accepted answer ...
cumanacr's user avatar
  • 391
23 votes
Accepted

Can I specify a specific time with seconds with Linux crontab?

Using systemd timer: https://wiki.archlinux.org/title/Systemd/Timers You can specify seconds as well: OnCalendar=Mon,Tue *-*-01..04 18:49:50 Or like this, 'hacking' crontab: 49 18 * * * sleep 50; mpv ...
Gilles Quénot's user avatar
11 votes
Accepted

Where is my crontab file on OS X?

Cron tabs are now stored in /var/at/tabs, which is a protected directory. You will need to change to a root shell in order to view them. They can be viewed by typing sudo su; cd /var/at/tabs; ls ...
Josh Correia's user avatar
7 votes

Run a cron job on the first Monday of every month?

Since I interpret my cron statements using php and js, I can't use bash. Finally I found that it is in fact possible with just cron: 0 30 8 * 1/1 MON#1 Hope this helps someone else. Regardless, I ...
kramer65's user avatar
  • 1,424
7 votes
Accepted

Run missed cronjobs when computer turns on

cron is not designed to do that, there are other tools that will, such as anacron. A workaround is to specify a task twice in the crontab, once at the time you want it to happen and again with the ...
LawrenceC's user avatar
  • 74.2k
7 votes

Can I specify a specific time with seconds with Linux crontab?

This command would play the "Donau.mp3" file at exactly 6:49pm. Not exactly 6:49pm, precisely 6:49pm. This is an important distinction that actually partly explains why most cron ...
Austin Hemmelgarn's user avatar
6 votes

Run a cron job on the first Monday of every month?

There is a hacky way to do this with a classic (Vixie, Debian) cron: 30 8 */100,1-7 * MON The day-of-month field starts with a star (*), and so cron considers it "unrestricted" and uses the ...
cuu508's user avatar
  • 302
6 votes
Accepted

Crontab: run a job once on Sunday and twice on the other week days

You must add another line in cron like: 0 16 * * 7 /path/to/command There is no way to do it in one line!
Romeo Ninov's user avatar
  • 6,455
6 votes
Accepted

Where is crontab's time command documented?

/bin/time. Not cron-specific, a general tool available on Unix-like systems. https://man7.org/linux/man-pages/man1/time.1.html See also: https://www.gnu.org/software/time/
ckhan's user avatar
  • 8,206
5 votes
Accepted

Why is the `cron.hourly` line in `/etc/crontab` the only one without `test -x /usr/sbin/anacron`?

Because the smallest period that Anacron is designed to work over is daily, so it can't be used to manage hourly cron jobs. Anacron is designed to handle a very specific use case, namely making sure ...
Austin Hemmelgarn's user avatar
4 votes

How to test cron @reboot entry?

crond is checking if the file /var/run/crond.reboot exists. If it exists, cron skips @reboot jobs sudo rm /var/run/crond.reboot sudo service cron restart
rundekugel's user avatar
4 votes
Accepted

How to log the output from an rsync backup which runs from a script using crontab?

Bassam: The rsync command has the --log-file option. In the manual entry: $ -> man -P cat rsync | grep 'log-file=FILE' --log-file=FILE log what we're doing to the specified ...
Adrian's user avatar
  • 362
4 votes
Accepted

how do I remove errant control characters from crontab

I can see the character $ at the end of each line, but I can't figure out how to remove it. That's supposed to be there. The $ at the end is how cat -e indicates a line break (the LF character). &...
grawity_u1686's user avatar
3 votes
Accepted

Do I need dedicated linux user for scheduled tasks?

It's always better to run things as a non-root user with exactly as much access and permissions as it needs, and nothing more. Whether it is "safe" to run something as root depends on what it does (...
SadBunny's user avatar
  • 1,416
3 votes

(Openwrt) How to set a service to automatically restart at a particular time in Luci Web interface Schedule tasks?

In the LEDE GUI, go to Schedule Tasks and then enter the following code (change the number for what time you want it to restart) # Reboot at 4am every day 0 4 * * * reboot
Jon Pienkowski's user avatar
3 votes

root crontab not executing

OK, I found what was not working for me: By tail'ing the /var/log/syslog, I discovered that crontab has a line size limit! So, when reading the line, it was stopping there: ... $(date +' making the ...
Stephane.P's user avatar
3 votes

Automating an ssh connection with crontab

This answer has another working solution: If you're using ssh-add to add your key(s) to the ssh agent, you can add the SSH_AUTH_SOCK environment variable to your crontab, and ssh commands there will ...
Quinn Comendant's user avatar
3 votes

Crontab not running python script, no errors no nothing

After a bit of discussion (see the comments above), it seems that the basic problem is that python writes its version text to stderr, not the expected stdout, where nothing is written, hence the empty ...
AFH's user avatar
  • 17.7k
3 votes
Accepted

Crontab doesn't execute any simple command

You should have: @reboot touch /home/pi/Documents/deleteme And you should have deleteme file in your /home/pi/Documents directory. What actually you're trying to do here is to update the date ...
Jarek Jóźwik's user avatar
3 votes

Command After Semicolon Not Executed in Crontab?

This question relates with this one: Running two commands sequentially in a cron job? You should separate the two commands with &&, instead of ;
j1b3's user avatar
  • 73
3 votes

Command After Semicolon Not Executed in Crontab?

This can be replicated by sh -c 'pkill -f "MyExecutable.exe" ; touch /tmp/here.log' Cron runs your command by passing it to a shell (sh or other), so effectively it's very similar to the above line. ...
Kamil Maciorowski's user avatar
3 votes

How to handle daylight savings in cron jobs

Run sudo dpkg-reconfigure tzdata and set local time zone (instead of UTC) you needed. Also setup and run ntp daemon that will synchronize time precisely and will switch between daytime saving time ...
Alex's user avatar
  • 6,255
3 votes
Accepted

Failure to change my desktop background via crontab

Yes, the gsettings command needs access to the D-Bus session bus of your desktop session. I'm not entirely sure of Ubuntu 18.04's architecture, but I think it was already fully systemd-based, so this ...
grawity_u1686's user avatar
3 votes
Accepted

"/usr/sbin/shutdown now" not working in crontab in WSL in win10

Unfortunately, there are a number of assumptions you are making in your question that just won't work. I'll cover each of those below. While this information is covered in other questions and ...
NotTheDr01ds's user avatar
  • 23.6k
3 votes

Is that anyway to use with crontab with two commands such as shutdown and run script after reboot?

First point, in crontab, you need to check the user that execute the command. You can list all crons jobs for a specific user like : crontab -u "user" -l sudo crontab -l # for root Second ...
hidigoudi's user avatar
  • 560
2 votes

I want to run an rsync command at midnight but make it stop at 8am. How can i schedule the start AND END of a command?

At some point fairly recently rsync added arguments for stopping at a fixed time. This means you can now call rsync --stop-at 08:00 which, provided you started running at midnight via cron will do ...
Flexo's user avatar
  • 2,377
2 votes

Set default editor for crontab -e invoked with sudo

Does this work for you? sudo VISUAL=vim crontab -e It works for me. (Debian 10 buster)
Hal Canary's user avatar
2 votes

Run a cron job on the first Monday of every month?

This answer expands on @ChiragPansheriya's answer to this same question. tl;dr Do a quick test of your cron implementation by pasting this into your crontab: # For 1st Monday (or Tuesday, etc) of ...
Robin A. Meade's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible