Questions tagged [cron]

Cron is a job scheduler that allows users to run commands periodically.

18
votes
2answers
4k views

Suppress output unless non-zero exit code

What's the best way to suppress output (stdout and stderr) unless the program exits with a non-zero code? I'm thinking: quiet_success() { file=$(mktemp) if ! "$@" > "$file" 2>&1; then ...
12
votes
4answers
4k views

Run Script once a day with systemd

I want to run a backup script 10 minutes after booting up my machine but only once a day. Is it possible to build up such scenarios with systemd?
7
votes
2answers
4k views

output of top gets truncated to 80 columns when run by cron

I have got the following logging script: #!/bin/bash top -b -c -n 1 >> /var/log/toplog/top.log And the following record in my crontab: */1 * * * * /home/clime/scripts/toplog.sh The ...
3
votes
2answers
581 views

cronjob to watch for runaway processes and kill them

I have a runaway ruby process - I know exactly how I trigger it. Point is, it got me thinking about runaway processes (CPU usage or memory usage). How would one monitor runaway processes with cron? ...
2
votes
1answer
1k views

Task not run by crontab

crontab strangely does not execute my script, although the script is running just fine from the shell terminal. I already made sure that scripts are separated from each other by a new line space. ...
1
vote
6answers
195 views

Trigger an action when an URL has been visited

Let's say I send an email, containing a link to my website, to someone that I really hope he'll visit it (fingers-crossed style): http://www.example.com/?utm_source=email392 or http://www.example....
1
vote
0answers
606 views

Schedule backup with notification?

To avoid editing files at the same time of backup scheduled by cron, I figure out a way: Before backup, send a desktop notification such as notify-send -t 0 "Ready for backup", to let me prepare (...
9
votes
1answer
11k views

The user x cannot use this program (crontab)

Ubuntu 14.04 I don't understand the behaviour I'm seeing with setting up crontab for a service (no login) account (named curator). When I'm logged in as root, this is what I get: # crontab -u ...
8
votes
3answers
20k views

Can I use logrotate to compress daily (date named) logs?

I have logs in the following format: YYYYMMDD I want to compress old logs (older then current day) and maybe move them to a different directory afterwards. Can I do this in logrotate, or do I have ...
4
votes
2answers
4k views

Can a crontab job run concurrently with itself?

If I have a crontab job that runs, for instance, every hour, but that job may take more than an hour to complete, will the next job fail to run?
4
votes
1answer
1k views

Should the key for an automatically running cron job that runs over ssh not have a passphrase?

I'm reading an article in Master Linux Now 2013 called OpenSSH: Easy Logins and it uses ssh-agent to allow you to enter a passphrase for your key once, and then you're able to connect to a remote ...
3
votes
2answers
1k views

Remove 50GB oldest files in busybox when used capacity reaches 95%

Ok I have requested a code here but initial I didn't ask to make it busybox compatible. My bad. I'm new to Linux and coding. The code needs to do the following: Delete 50GB of oldest data (dir ...
3
votes
1answer
7k views

“stdin: is not a tty” mails for running scripts as cron jobs

I have several shell scripts (bash) which are started by cron. Every time a script is executed I get an email saying "stdin: is not a tty". Can someone please tell me how to fix this? All scripts run ...
3
votes
1answer
7k views

How to schedule shutdown every day?

We have a server that is used for Linux thin clients in a class. The server is started when required and I want to schedule it to power off at 22:00 every day to avoid power wasting. I thought of ...
2
votes
2answers
691 views

Changing user's wallpaper via system crontab

I tried to set up wallpaper change via cron in /etc/crontab, but I failed. DISPLAY env set directly / before cmd, but still it's not working: DISPLAY=:0.0 * * * * * ad env DISPLAY=:0.0 /usr/bin/...
2
votes
1answer
707 views

To write this Pseudocode with Regex

I am doing a Makefile which I run regularly by Crontab every day at 0230 crontab -e; 30 2 * * * /bin/thePseudocode Python-like Pseudocode directories = ["Cardiology", "Rheumatology", "Surgery"] for ...
2
votes
1answer
387 views

Qt program not invoked by cron

I had a simple Qt program, when running, it shows a simple window with a countdown timer. If you might be interested in the code, please see here. I had crontab line * * * * * /home/my-user-name/...
2
votes
1answer
1k views

Kubuntu 18.04, cron task does not load @reboot

I am running Kubuntu 18.04, and have a simple script to reset the plasmashell every time after suspend/lockscreen since there's a known bug that corrupts folder/file names upon returning from suspend. ...
2
votes
2answers
64 views

Can I schedule running a script inside a particular shell process once in a while?

cron can be used to schedule running a program once in a while. But it seems to be not specific to an existing shell process. If I have a script which accesses the state of a specific bash process (e....
2
votes
4answers
3k views

Anacron job complains “Gtk-WARNING **: cannot open display”

I'm trying to make a simple weekly Anacron job that backs up my computer if I click yes on the dialog. The script I wrote works fine if run manually, but when Anacron runs it, nothing happens and I ...
2
votes
1answer
2k views

Running a cron job randomly for every one hour

I want a cronjob to run every one hour randomly. (i.e if the first job runs at 58 minutes,the second job should run at 47 minutes and the third one at 52 minutes and so on) But this should run ...
2
votes
1answer
3k views

Can't use `source` from cron?

I'm setting up a docker container which requires a cronjob to do a backup using awscli. I'm having a problem with the cron job being able to access the environment variables of the docker container. ...
1
vote
1answer
861 views

Where does cron log by default?

On Ubuntu 18.04, man cron says cron logs its action to the syslog facility 'cron', and logging may be controlled using the standard syslogd(8) facility Also, the default configuration of ...
1
vote
1answer
189 views

how to manage cleaning of /tmp better on hadoop machines

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 ...
1
vote
2answers
12k views

Run a cron job every minute, meaning of syntax [duplicate]

I read somewhere that you can add a cron job to run every minute like this: #min hour day month weekday command */1 * * * * <your command> What does the /1 part mean? Can I omit ...
1
vote
1answer
316 views

`crontab -e` “ruins” terminal

After running crontab -e, My terminal starts acting strange, where characters aren't printed in the correct position. Starting and exiting an ncurses application (like vim and nano) doesn't help, nor ...
1
vote
1answer
751 views

Differences between `/etc/crontab`, files under `/etc/cron.d/` and `/var/spool/cron/crontabs/root`?

What is the difference between the purposes of /etc/crontab files under /etc/cron.d/ /var/spool/cron/crontabs/root If you want to add a cron job, into which file would you add it? manpage of cron(...
12
votes
1answer
10k views

Cron job does not fire up after a timezone change

I've tried eliminating many of the common errors, ensuring that the PATHs are available for cron there is an endline at the end of crontab file the timezone is set-up by: cd /etc cp /usr/share/...
12
votes
2answers
2k views

How does anacron work if it's not a daemon?

I was reading about the differences between cron and anacron and I realized that anacron, unlike cron is not a daemon. So I'm wondering how does it work actually if it's not a daemon.
9
votes
1answer
1k views

Finding which cron jobs are scheduled to run at some future date/time X

Is there a way to "query" a crontab to find which cron jobs run at some arbitrary date/time, or during a certain range of times? For example, determine which will be run at sometime between 14:00 and ...
5
votes
3answers
3k views

Frustrating issue where neither cron nor su -c runs my job (permissions?)

Updated (and snipped) with more details below. I've set up a cron script and I'm trying to debug why it's not running. [Snipped context testing, which is all ok; see revision 2 for details] The ...
5
votes
2answers
782 views

Best way to ensure that a script is run once a period?

I need a certain script to run once a month (others viewing this question may need it to be run once a day/week/year/5-day, etc). I know I can use cron to do so with: 0 0 1 * * ./script.sh But what ...
4
votes
3answers
9k views

Cron job to check if PHP script is running, if not then run

I am wondering if someone might point me in the right direction. I've got little experience working with the Linux command line and recently due to various factors in work I've been required to gain ...
3
votes
1answer
820 views

Prevent gnome-pty-helper from running again

I terminated the gnome-pty-helper process with $ kill -9 9753 After a while it was running again with another process number. There wasn't a restart of a system. Why is it located under ~/.config/...
3
votes
1answer
2k views

Are changes in crontab applied when the file is saved, or when the editor is closed?

When I do crontab -e, are the changes applied immediately when I save the file, or do I have to exit vim for it to be applied?
3
votes
1answer
110 views

fault-tolerant crond replacement

I'm looking for a replacement to crond, or possibly an extension of it. The feature that I definitely would want to have is fault-tolerance. E.g. if a job failed to run due to the computer not being ...
3
votes
1answer
771 views

Solaris cron ignoring mail aliases?

As a Solaris user, I want cron jobs generated emails for the localuser@server to be forwarded to my myuser@sample.com email account, so that I read only one inbox. To resolve this I have forwarded ...
3
votes
1answer
1k views

ls gives me different sort orders during a cron job

I have a cron job that, among other things, does a recursive ls of a directory into a file. This gets compared to another file that I've created that, supposedly, contains an identical listing of the ...
3
votes
2answers
124 views

wget saving files as emply plain text files on boot

I have a bash script in crontab that runs @reboot: The script itself contains a wget command to pull and download a file from the internet When I run my script after signing in and opening the ...
2
votes
3answers
1k views

Why does Crontab give me an error with my PHP script when running it from the terminal does not?

I'm having some problems with running the Crontab with PHP files. I have this same php scripts running in the Crontab for more than 6 months but some days ago mysteriously they stopped to execute the ...
2
votes
1answer
2k views

Absolute path in bash scripts

I've got a shell script myscript.sh which calls a command, let's say mycmd. When i run that script from the terminal, e.g. ./myscript.sh, everything works fine. But when i add that script to the ...
2
votes
1answer
2k views

How do I run a cronjob on a display? [duplicate]

I've added the (f)cronjob */1 * * * * DISPLAY=:0 notify-send testing to display a notification every minute, but it doesn't work; why not? (Using i3.)
2
votes
1answer
5k views

Crontab does not run?

crontab -e 0 */4 * * * root /usr/bin/rsnapshot hourly 30 3 * * * root /usr/bin/rsnapshot daily 0 3 * * 1 root /usr/bin/rsnapshot weekly 30 2 1 * * root /usr/bin/rsnapshot monthly tail /var/log/cron ...
2
votes
4answers
2k views

How to schedule cronjob for every 45 days?

How to execute a shell script via a cronjob every 45 days?
2
votes
1answer
790 views

XRandR script runs correctly from command line, fails as cron job

I'm running LXDE on Fedora 21. My script's purpose is to extend the display across two monitors: #!/bin/sh xrandr --output VIRTUAL1 --off --output LVDS1 --mode 1440x900 --pos 1280x124 --rotate normal ...
2
votes
1answer
385 views

Crontab resetting itself

I have a computer with Ubuntu server 15.10 installed on it that sits in the same room I am in. I use it just as a Minecraft server, map renderer and whatever else php scripts I want to run scheduled ...
2
votes
0answers
481 views

filter cron emails through procmail?

I'm using postfix/mutt/procmail on a Linux/Debian and I've some trouble filtering cron emails with procmail, I just want to move them to the cron/ maildir directory, but no lucky till now. I've ...
2
votes
1answer
353 views

cron job not running from cron.daily

I have added a job (register-dns.cron) to /etc/cron.daily/, but it is not running. The result of some testing is shown below. #↳ ls -l /etc/cron.daily/ total 28 -rwxr-xr-x 18 root root 1474 Sep 13 ...
2
votes
3answers
477 views

Read each directory and perform actions in Bash script

I have this directory structure at /var/sync: # tree -d /var/sync/ /var/sync/ ├── sync_bi │   ├── replicator => Replicator.php │ sync.php ├── sync_pfizer │   ├── replicator => Replicator.php ...
1
vote
2answers
6k views

Cron several script every 5 minutes with 10 second between each script

I have several file setup in my crontab, all those scripts must run every 5 minutes. The problem comes when those script need to much CPU and IO at a time and the machine become unavailable. To ...