date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,324,046,017,000
I have created a --user service in systemd such that a non privileged user can manage a service. This works well. I wanted to restart the service at a fixed given time of day, so i created a cron job in the users crontab. Strangely this does not work. The user can restart the service if they run: systemctl --user rest...
systemctl --user needs to talk to the D-Bus session, which involves setting at least DBUS_SESSION_BUS_ADDRESS and perhaps XDG_RUNTIME_DIR; typically: XDG_RUNTIME_DIR=/run/user/$(id -u) DBUS_SESSION_BUS_ADDRESS=unix:path=${XDG_RUNTIME_DIR}/bus export DBUS_SESSION_BUS_ADDRESS XDG_RUNTIME_DIR systemctl --user restart mys...
Using Cron to restart a systemd user service
1,324,046,017,000
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. As I work around on startup I print all environment variables to a file printenv > /env. When I try to use source from t...
First of all, the command's (well, shell builtin's) name is source. Unless you have written a script called source and put it in /, you want source and not /source. The next issue is that cron usually uses whatever you have as /bin/sh and source is a bashism (or other such more complex shells). The portable, POSIX-co...
Can't use `source` from cron?
1,324,046,017,000
I would like to send an email when a file reach a certain size limit. The only way I thought of doing this is by doing a cronjob which will check the file size and send the email if the file is bigger than the desired size. However, it seems like a bad solution for me to add a cronjob which would check ,for example ev...
I can conceive of 2 approaches to do this. You can either use a while loop which would run a "stat" command at some set frequency, performing a check to see if the file's size has exceeded your desired size. If it has, then send an email. This method is OK but can be a bit inefficient since it's going to run the "stat...
Automatically detect when a file has reached a size limit
1,324,046,017,000
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 to use a custom script in cron?
Here's a quickie script which will do what you need: #!/bin/bash LOGDIR=/var/log/somedir OLDLOGS=/var/log/keep-old-logs-here PATH=/bin:$PATH TODAY=$(date +'%Y%m%d') [ -d $OLDLOGS ] || mkdir -p $OLDLOGS cd $LOGDIR for LOG in $(ls | egrep '^[[:digit:]]{8}$'); do [ $LOG -lt $TODAY ] && gzip $LOG && mv $LOG.gz don...
Can I use logrotate to compress daily (date named) logs?
1,324,046,017,000
I write a script and set it as a cron job. But due to a difference of environment variables it doesn't work as it should be. In that case I change a little bit with crontab -e and set a cron job time closest minute, and wait next minute to come to show the result. I feel this is a totally absurd approach, but I don't ...
Here is how to do the other way around: forcing cron execution to use your login environment: bash -lc "your_command" From the bash manual: -c string If the -c option is present, then commands are read from string. If there are arguments after the string, they are assigned to the posit...
How to run a command as if it is called from cron
1,324,046,017,000
On a server I inherited, there is a cron job running hourly on one of the Debian servers. It sends an email out to a non-existent email, but bounces back to my account since I listed myself as the root email in /etc/aliases. The cron job has been deleted from /etc/cron.hourly (it was ntupdate), as it's listed in the e...
system crons Did you look through these files & directories to make sure there isn't a duplicate cronjob present? /etc/crontab /etc/cron.hourly/ /etc/cron.d/ /etc/cron.daily/ /etc/cron.hourly/ /etc/cron.monthly/ /etc/cron.weekly/ Also any files present in these directories that's executable will be run. Doesn't matt...
Cron job still running when deleted
1,324,046,017,000
I read from an instruction to schedule a script on the last day of the month: Note: The astute reader might be wondering just how you would be able to set a command to execute on the last day of every month because you can’t set the dayofmonth value to cover every month. This problem has plagued Linux and Unix progra...
Abstract The correct code should be: #!/bin/sh [ "$#" -eq 0 ] && echo "Usage: $0 command [args]" && exit 1 [ "$(date -d tomorrow +'%d')" = 01 ] || exit 0 exec "$@" Call this script end_of_month.sh and the call in cron is simply: 00 12 28-31 * * /path/to/script/end_of_month.sh command That would run the script end_of...
Schedule the last day of every month
1,431,943,225,000
I think about doing something like: sudo ln -s ~/myCustomCrontab /var/spool/cron/crontabs/username because I'd like to have all customized files in my home directory. Possible risks I can think of are security (How should the permissions be to still be secure?) system failure Or is there a better way to "keep track...
This does not work, at least in Debian-like systems (symlinked or hardlinked crontab files for (not-system) users are ignored at all). It also fails if you use crontab to change your crontab file. If the cron version still accepts symlinked crontab files, it creates possible security holes as the crontab file is not c...
Is it evil to link to a crontab?
1,431,943,225,000
I want to know how cron works internally. Does the process keep checking the current time in an infinite while loop (thus continually consuming CPU cycles)? Or does some function generate an interrupt and notifies the cron daemon ?
I once read the vixie-cron source code and had to be hospitalized. However if you're looking for "some function generate an interrupt" at a time in the future, you should investigate the alarm(2) syscall. It asks the kernel to send you the signal SIGALRM at a scheduled time, which you can then catch. In the mean time,...
How do the internals of the cron daemon work?
1,431,943,225,000
My cronjob looks like this: 5 3 * * * mysqldump -u root test > /srv/backup/mysql_daily.dump How can I make filename unique for every time when cronjob writes mysql_daily.dump?
For bash, maybe: ... > /srv/backup/mysql_daily-$(date -u +\%Y\%m\%dT\%H\%M\%S)Z.${RANDOM}.dump Personally, i generally only put simple commands in my crontab. I'd put this in a little script and use the script in the crontab. This would have the benefit of not requiring the % characters to be escaped (a common cronta...
How to add unique id to file name in cron job?
1,431,943,225,000
I'm looking for a way to schedule when an external hard drive connected to my Linux (Debian 9) box goes to sleep (stops spinning). To put this into content: I have a Linux box that runs as a multimedia server. If a call is made to fetch content that is on the external hard drive, it often takes 15-30 seconds for the ...
A cronjob would allow this: # At 11pm every day, enable sleep after 30s 0 23 * * * /sbin/hdparm -S6 /dev/disk/by-id/... # At 5pm on weekdays, disable sleeping 0 17 * * 1-5 /sbin/hdparm -S0 /dev/disk/by-id/... # At 3pm on the weekend, disable sleeping 0 15 * * 0,6 /sbin/hdparm -S0 /dev/disk/by-id/...
Is it possible to (7 day) schedule sleep time of a hard drive?
1,431,943,225,000
I can run a script at boot by adding the following line to my crontab: @reboot perl /path/script That works fine. But the problem arises when I try to run a gui application such as gmail notify. It simply doesn't run. How do I run a gui application on startup?
Cron is not the program you're after. To run GUI programs there are different approaches. Which one to choose depends on your desktop environment. The traditional way is to hook it into your .xinitrc file before starting the window manager. A simple example .xinitrc looks as follows: #!/bin/sh # Play a login sound og...
Run gui application on startup
1,431,943,225,000
I recently came up to an easy fix for a crontab logging issue and I am wondering what are the pro's and con's of using this specific fix (running a script with a "login shell flag"), as: #!/bin/bash -l
[The following assumes that your unspecified "logging issue" was related to missing environment setup, normally inherited from your profile.] The -l option tells bash to read all the various "profile" scripts, from /etc and from your home directory. Bash normally only does this for interactive sessions (in which bash ...
What are the pro's and con's in using the "-l" in a script shebang
1,431,943,225,000
I'm using Amazon Linux and trying to run a cron job from my home directory (I don't have sudo permissions on the machine). I'm setting a cron job by executing crontab -e and adding this line 30 18 * * * /home/myuser/run_my_script.sh within it. However, I'm observing that things don't seem to be running, so I wanted...
Add to the end of your cron table entry: >> /home/myuser/myscript.log 2>&1 This will capture the output to a log file. By default, the output is mailed using the local mailer daemon to the user who owns the job, but I am not certain this daemon is running by default on an AWS instance. If it is, try running mail as...
How do I get the output of a cron script run from my home directory?
1,431,943,225,000
I want to add a cron entry that does something like: 00 00 * * * * /tmp/script.sh Is there something I can add to the end of the line, so that when it is finished, it will remove the line out of my cron? Also, if there is a better way to do it, I would definitely want that information instead.
Cron is used to schedule a job to run repeatedly. What you want is at, which schedules a job to run one-time. For your example you can write: at midnight This will bring up an interactive prompt where you can enter /tmp/script.sh followed by Ctrl+D.
Cronjob to Run and then Terminate
1,431,943,225,000
I'd like to know if L is one of the allowed special characters on Debian's cron implementation? I'm trying to set up a cron to run on the last day of every month. From the cron entry on wikipedia: 'L' stands for "last". When used in the day-of-week field, it allows you to specify constructs such as "the last Friday...
Cron entries on Debian are described in the crontab man page (man 5 crontab). Debian uses Vixie's cron, and his man page says: The crontab syntax does not make it possible to define all possible periods one could image off. For example, it is not straightforward to define the last weekday of a month. If ...
Cron allowed special character "L" for "Last day of the month" on Debian
1,431,943,225,000
I have a script containing: #!/bin/bash printenv When I run it from the command line: env testscript.sh bash testscript.sh sh testscript.sh every time, it outputs SHELL=/bin/bash. However, when it is run from the cron, it always outputs SHELL=/bin/sh. Why is this? How can I make cron apply the shebang? I already che...
The shebang is working and cron has nothing to do with that. When a file is executed, if that file's content begins with #!, the kernel executes the file specified on the #! line and passes it the original file as an argument. Your problem is that you seem to believe that SHELL in a shell script reflects the shell tha...
Shebang does not set SHELL in cron
1,431,943,225,000
I've created a simple script to check the value of an environment variable when run from crontab: #!bin/bash echo $USER > cron.txt I save this as script.sh in my home directory. If I run it manually, cron.txt contains my username, as I would expect. I then add a line to my crontab: */1 * * * * ./script.sh I again ex...
When the cron execute your job, it does so in an environment that is not the same as your current shell environment. This means, for example, that ./script.sh may not be found. There are two solutions: */1 * * * * ( cd $HOME/mydir && ./script.sh ) or */1 * * * * $HOME/mydir/script.sh I.e., specify exactly where the ...
$USER environment variable is undefined when running script from crontab
1,431,943,225,000
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 problem is that lines in top.log are being cut to 80 chars, e.g.: 1512 root 20 0 80756 1436 572 S 0.0 0.1 0:05.92 /usr/...
top always displays spaces until the last screen column. You just don't realize it when it's printing to the terminal because you can't visually distinguish a line with trailing spaces from a line without trailing space. You'll notice the spaces if you copy-paste with the mouse or in screen. If you want to get rid of ...
output of top gets truncated to 80 columns when run by cron
1,431,943,225,000
My syslog is chock-full of the following: Oct 28 23:35:01 myhost CRON[17705]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1) Oct 28 23:45:01 myhost CRON[18392]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1) and also some Oct 28 23:59:01 myhost CRON[19251]: (root) CMD (command -v d...
These commands are, indeed, part of the sysstat package. It's intended for performance monitoring; and specifically, sar is the system activity report: a Unix System V-derived system monitor command used to report on various system loads, including CPU activity, memory/paging, interrupts, device load, network and swa...
Can I avoid debian-sa1 lines in my syslog?
1,431,943,225,000
I cannot find anywhere the log level meaning of crond. I know that 0 is pretty much "log everything" while 8 is "show only important info" thanks to the crond help: / # crond --help BusyBox v1.26.2 (2017-11-23 08:40:54 GMT) multi-call binary. Usage: crond -fbS -l N -d N -L LOGFILE -c DIR -f Foreground -...
The particular semantics of the log level values for crond are only defined in the code, it seems. All of the crond logging there goes through a crondlog() function in busybox/miscutils/crond.c function: static void crondlog(unsigned level, const char *msg, va_list va) { if (level >= G.log_level) { /* Do...
crond log level meaning
1,431,943,225,000
I have several questions related to non-interactive, non-login shells and cron jobs. Q1. I have read that non-interactive, non-login shells only "load" $BASH_ENV. What does this exactly mean? Does it mean that I can point $BASH_ENV to a file, and that this file will be sourced? Q2: Assuming that I have an entry in c...
For Q1 & Q2, see here. Q3 is answered in the discussion of your other three questions below. WRT $BASH_ENV, from man bash: When bash is started non-interactively, to run a shell script, for example, it looks for the variable BASH_ENV in the environment, expands its value if it appears there, and uses the ...
BASH_ENV and cron jobs
1,431,943,225,000
This command, when run alone, produces the expected result (the last line of the crontab): tail -n 1 /etc/crontab However, when I run it as part of an echo command to send the result to a file, it adds a summary of all the files in the working directory, plus the expected result: sudo bash -c 'echo $(tail -n 1 /etc/c...
Your crontab line has one or more asterisks * in it, indicating "any time". When that line is substituted in from the command substitution, the result is something like echo * * * * * cmd > /path/to/file While most further expansions are not applied to the output of command substitution, pathname expansion is (as is ...
Echoing a tail command produces unexpected output?
1,431,943,225,000
How to execute a shell script via a cronjob every 45 days?
If you don't need exactly 45 days, but "one and a half months" will do, then a straightforward method would be to run at the beginning of the month every three months, and at the middle of the next month after each of those: 0 12 1 1,4,7,10 * /path/to/script 0 12 16 2,5,8,11 * /path/to/script For general arbitrary...
How to schedule cronjob for every 45 days?
1,431,943,225,000
I have a cron setup to execute a bash script daily at 10pm. I have another cron setup to run monthly on the 1st of the month. Both crons launch a bash script, and the only different in the bash script is the argument they pass into the underlying java program (emulating command line launch of the java program). The p...
In a similar vein to the solution proposed by @StephaneChazelas in the comments you could specify the range of days in the 3rd field as a range for the cron that you want to run on every day besides the 1st of the month. The following two entries would accomplish what you're after: 0 22 1 * * /path/to/script/1...
Cron to not run on specific day but all other days
1,431,943,225,000
I would like to use git to track changes in crontab. I have initialized a new git repository in /var/spool/cron/crontabs/ Now the problem is, when crontab is saved, the second line of the header changes because it contains timestamp. # DO NOT EDIT THIS FILE - edit the master and reinstall. # (/tmp/crontab.ubNueW/cront...
You could use a filter: git config filter.dropSecondLine.clean "sed '2d'" Edit/create .git/info/attributes and add: * filter=dropSecondLine If you don't want the filter acting on all the files in the repo, modify the * to match an appropriate pattern or filename. The effect will be the working directory will remain ...
tracking crontab changes with git
1,431,943,225,000
Ok, so I've just had a read through this page after a way to improve my current backup solution on my Debian server. Tar seems to be offering a quite nice multi-volume feature, although when I try it out, it asks me to Prepare volume #X for ‘mybackup.tar.gz’ and hit return:. How should I automate this as I would like ...
Here is a solution: printf 'n file-%02d.tar\n' {2..100} | tar -ML 716800 -cf file-01.tar Documents/ 2>/dev/null where 100 is a number greater or equal to the number of volumes. Edit Setting a big number should not be a problem, though I tend to not take a ridiculous one. An alternative could be a "next volume" s...
Can I automate tar's multi-volume-feature?
1,431,943,225,000
I am trying to run a bash script I have via cron, and I am getting the following error at the beginning of the execution: tput: No value for $TERM and no -T specified Here is what is in my crontab: 0 8 * * 1-5 cd /var/www/inv/ && /var/www/inv/unitTest run all 2>&1| mail -r "[email protected]" -s "Daily Inventory Unit...
Your unit test script probably calls tput in order to generate pretty output showing which tests pass and fail. Under cron there is no terminal and thus no terminal type ($TERM), so tput cannot control the nonexistent terminal. Your unit test script needs to have 2 modes: running on a terminal: it can call tput to ge...
tput: No value for $TERM and no -T specified
1,431,943,225,000
I have been reading on OnCalendar= Sadly, I found no info on how to schedule an event on a day other way than defining a day of the week, which would make it run every week at the rarest. I need it to run every, say, 14 days. And at a specified hour (say, 4am). Is this possible with systemd?
I need it to run every, say, 14 days. And at a specified hour (say, 4am). Is this possible with systemd? The easiest way to get approximately every 14 days is to make it twice a month. [Install] WantedBy=default.target [Unit] Description=Every fortnight. [Timer] OnCalendar=*-*-1,15 4:00:00 Unit=whatever.service T...
systemd timer every X days at 04:00
1,431,943,225,000
I created a cronjob, it runs for a very long time but now don't know how to stop it.
You should stop the process that the crontab started running. #kill -HUP PID (PID: Process ID is the process running) To see a relation of the PID with the running processes (and more info) use top command, change the column order with the keys < and > Also try ps -ax|grep [your_process_file] which lists the running ...
List currently running cron tab and stop it
1,431,943,225,000
It seems Linux Mint 19.3 Tricia Cinnamon wants to clear out PHP session files every half-hour. How do I: Remove this task from the scheduler's awareness, and Not have to reboot the computer to do so. I found the crontab file at /etc/cron.d/php. I edited the file by making the relevant line a comment. I expected that...
The phpsessionclean scripts as delivered by upstream Debian will either use cron if there is no systemd present, or will use systemd for scheduling if it is available. This is apparent in the cronjob test if [ ! -d /run/systemd/system ] which checks if systemd has been initialized on this system. When systemd is avail...
How to remove cron task that deletes PHP sessions
1,431,943,225,000
I read about the following 2 ways to run multiple commands in a single cron job: We can run several commands in the same cron job by separating them with a semi-colon (;). * * * * * /path/to/command-1; /path/to/command-2 If the running commands depend on each other, we can use double ampersand (&&) between them. ...
Yes, using ; between the commands will guarantee that all commands are run sequentially, one after the other. The execution of one command would not depend on the exit status of the previous one. As pointed out by Paul_Pedant in comments, doing anything more complicated than launching a single command from crontab ma...
Multiple, sequential commands in cron [duplicate]
1,431,943,225,000
Yeah, I know it's classic. I've googled it all around, but still it doesn't work. I have the following script: #First go to SVN repo folder cd $svnrepos # Just make sure we have write access to backup-folder if [ -d "$bakdest" ] && [ -w "$bakdest" ] ; then # Now $repo has folder names = project names for repo i...
The issue is that you are probably running ssh-agent in your interactive environment but do not in cron and that your ssh key filename is different from the default filenames. To solve this you can either explicitly specify the ssh key in your scp commandline, i.e. scp -i $SSH_KEY_FILENAME or specify an appropriate ~/...
Scp doesn't work in cron
1,431,943,225,000
I had a problem that gmail was blocking emails sent using mailx. I solved this by setting up an appropriate ~/.mailrc, which looks like: set smtp-use-starttls set nss-config-dir=/home/theuser/.certs set ssl-verify=ignore set smtp=smtp://smtp.gmail.com:587 set smtp-auth=login set smtp-auth-user=xxx set smtp-auth-passwo...
mailx only sends mail if you pass it the destination address on the command line. When you run it with no arguments, it reads interactive commands from its standard input. Beware that your tests fed it garbage which has been interpreted as commands; some of these commands may have corrupted your mailboxes, sent out em...
Calling mailx from crond
1,431,943,225,000
Is it possible to check for a file existence in a crontab oneliner, and only execute a script if that file existed? Pseudocode: * * * * * <if /tmp/signal.txt exists> run /opt/myscript.sh
You can't technically avoid running a cron job depending on the existence of a file, but you can let the job test whether the file exists and then take further actions based on the outcome of that test. Use an ordinary test for existence, then run the script if the test succeeds. * * * * * if [ -e /tmp/signal.tx...
How to run a crontab job only if a file exists?
1,431,943,225,000
I would like to backup a folder using cron on a centos. The folder c2duo_mms is located in /usr/local/src/djcode/c2duo_mms. I would like it backed ip every 1:00pm on Tuedays to my home folder /home/sh.
A good thing to do would be to create a new compressed archive in your home. Create this script named for exmaple */home/sh/c2duo_mms_backup.sh*: #!/bin/bash cd /usr/local/src/djcode/ tar zcf /home/sh/c2duo_mms-`date +%Y%m%d`.tar.gz c2duo_mms Be sure to add the executable permission to the script: chmod +x /home/sh/...
linux cron: want to backup a folder
1,431,943,225,000
I am on Arch Linux and I'm trying to make a cron job that fires every minute. So I use: $ crontab -e And add the script in: * * * * * Rscript /srv/shiny-system/cron/CPU.R ~ ~ "/tmp/crontab.8VZ7vq" 1 line, 47 characters (I have no idea what that "/tmp/crontab.8VZ7vq" is!) But it is not working - CPU.R is not running...
There is no crond.service on Arch Linux. As the Arch Wiki makes perfectly clear: There are many cron implementations, but none of them are installed by default as the base system uses systemd/Timers instead. Consequently, if you want to use cron, you have to choose which of the many implementations you will instal...
Arch Linux - How to run a cron job?
1,431,943,225,000
For testing purposes ,I would like to run a command check every 15 minutes past the hour. I'm a little bit confused about the correct timeframe syntax of the crontab : Is this correct : */15 * * * * or this one : 15 * * * * I think its the first one ,since the second will run 15 minutes (once) after 1 hour passed....
The first one will (with most common cron implementations) run the command every 15 minutes and is equivalent to 0,15,30,45 * * * *. The second one will run 15 minutes past the hour, every hour. This is described in the crontab(5) manual on your system (man 5 crontab).
Crontab past the hour
1,431,943,225,000
I installed the python-certbot-apache package per the instructions on certbot.eff.org but can't find any entry for the cron job its supposed to set up. The Certbot packages on your system come with a cron job that will renew your certificates automatically before they expire. Since Let's Encrypt certificates last for...
In any Debian derivate, to list the files installed for a package you usually do dpkg -L. So in your case: dpkg -L python-certbot-apache This is give you the list of all files installed, and where. You can also request the list of files from packages.debian.org From https://packages.debian.org/stretch/all/python-cer...
Debian and Certbot: where does the package install the cron job?
1,431,943,225,000
I want to set up up yum to auto update the system using yum-cron. But my internet connection is very limited and I don't want the update process to hog the tiny bit of internet that is available and make the computer usage for everybody on the network miserable. How can I set up yum to check and download updates autom...
Well, if it were me, I would set up a cron job (for root) that starts at 2am every day. Like so: 0 2 * * * /bin/yum -y update It's about as KISS as it can get!
How to schedule yum auto update to run only during the night?
1,450,463,937,000
What is needed to give cron commands access to the session bus (if it is running)? It used to work for me, on Debian Stretch (testing) since switching systemd until relatively recently (might have been month or two ago). The strange thing is that while I strongly suspect this is controlled by the PAM configuration, th...
This is likely due to the fact that the DBUS_SESSION_BUS_ADDRESS environment variable isn't propagated to the cron environment. At least under Gnome, the bus isn't made "discoverable" (as documented in the "AUTOMATIC LAUNCHING" section of the dbus-launch(1) man page) via files in $HOME/.dbus/session-bus. This leaves a...
Access to user's session D-bus from their cron commands
1,450,463,937,000
I'd like to know how I can check to see if my cronjob will run at the specified time I set it at. Is there anyway I can test this without having to wait for that time? Here are my crontab -l results: root@work:~$ crontab -l 3 */23 * * * /opt/lampp/bin/php /opt/lampp/htdocs/site/cron/my_script.php > /dev/null If I did...
The only way to be sure is to let it run and inspect the results. You can modify your command to log the output somewhere and inspect that, or let it email you the output. You could add another identical line which runs the command within 5 minutes or so, for debugging. eg. If it's 3:13 pm right now, I might add this...
How can I ensure my cronjob will run at specified time?
1,450,463,937,000
This is the first time I'm using cron through its /etc/cron.hourly directory to run a script once every hour. For some reason, the script doesn't seem to run. Here's what I did: Added a basic test script in /etc/cron.hour: /etc/cron.hourly# ll -rwxr-xr-x 1 root root 152 Jun 20 23:26 test.bash* Here's the script: /e...
Which distribution are you using? According to Ubuntu's run-parts manual: If neither the --lsbsysinit option nor the --regex option is given then the names must consist entirely of ASCII upper- and lower-case letters, ASCII digits, ASCII underscores, and ASCII minus-hyphens. Therefore run-parts won't run a scri...
Why doesn't cron run a test script from /etc/cron.hourly?
1,450,463,937,000
I am trying to create a directory having a timestamp in its in name in the /home directory. I have created the following cron job as the root user, but it's not running. What am I doing wrong? Following is my cron job which I have created with root user privilege. [root@bvdv-emmws01 home]# crontab -l * * * * * /home/...
A crontab created with crontab -e and listable with crontab -l should not have a user specified for the command. Your entry should read: * * * * * /home/test.sh Or alternatively put the line that you have in /etc/crontab instead. From man 5 crontab (section EXAMPLE SYSTEM CRON FILE): # /etc/crontab: system-wide cront...
How to run a cron job to execute every minute?
1,450,463,937,000
How to set default umask for cron jobs, please? (On RHEL 6.) Jobs are started under non-interactive (obviously) no-login (?) shell. Not only I prefer dash over bash. But consider also bash called as /bin/sh. It seems, that both shells in non-interactive no-login invocation doesn't read any start-up file like /etc/prof...
On RHEL, PAM is used, so you could try using pam_umask Try putting this in /etc/pam.d/crond session optional pam_umask.so umask=0022 Naturally, this is untested, and may very well break assumptions made by various applications.
Default umask for cron jobs
1,450,463,937,000
Is there any difference between creating a CRON tab using 0/5 and */5? For example: 0/5 * * * * vs */5 * * * *
This IBM support article explains how stepping works. In the case of */5, it would occur every 5 minutes (0, 5, 10, etc). That is the same as 0-59/5. In the case of 0/5, I just tested it and it will never run.
Difference between CRON tab 0/5 and */5?
1,450,463,937,000
I can run the command aws --version in a script and in the cli. But if I put this command into a crontab it does not work. Crontab: 50 12 * * * aws --version > ~/yolo.swag Error: /bin/sh: 1: aws: not found The aws command is in a bash script. And I get the same error message when I run the script in cron. How can I ...
You need to specify the full path to the aws executable: 50 12 * * * /usr/local/bin/aws --version > ~/yolo.swag
AWS CLI - not working in a crontab
1,450,463,937,000
I have a script in /etc/cron.hourly : -rwxr-xr-x 1 root root 85 Dec 6 19:05 /etc/cron.hourly/nvidia_to_exclusive containing (with an empty line at the end): #!/bin/bash /usr/bin/nvidia-smi -c 1 > /home/user/nvidia-smi_set_exclusive.log The script isn't executed by cron at all, even if using run-parts /etc/cron.ho...
The problem was that the cron service was inactive. While I'm here, I'll summarize all the steps I've found to make a script in /etc/cron.hourly/ work : Check that the name of your script is only using valid characters for run-parts, i.e. [a-zA-Z0-9_-]. So don't use extension like .sh. Check that your script is ex...
Script in /etc/cron.hourly/ never running
1,450,463,937,000
I'm new on linux user I try to run crontab to backup my database with vagrant user * * * * * /usr/bin/mysqldump -h localhost -u root -p root mydb | gzip > /var/backup/all/database_`date +%Y-%m-%d`.sql.gz >/dev/null 2>&1 when the crontab runs there is no backup file in the folder (my backup/all has the permission sch...
Of course, the error is that you don't have a mailer (sendmail,postfix, etc) implemented and active. That being said your other problem is that the >/dev/null 2>&1 ONLY only applies/associates to the LAST command in this case gzip. Thus there must be some type of output going to STDERR for your mysqldump. The corre...
crontab error with (No MTA installed) but I use >/dev/null 2>&1
1,450,463,937,000
I'm trying to set up a cron job under my user. I run crontab -e, make my edits, and try to save and exit. I receive the following error message /var/spool/cron/: mkstemp: Permission denied. Relevant output from ls -al /var/spool/cron/crontabs drwxr-xr-x 2 root crontab 4096 Nov 4 10:09 . drwxr-xr-x 5 root root 409...
This will fix your immediate problem: chmod u=rwx,g=wx,o=t /var/spool/cron/crontabs But, if you can download packages, a more robust way to fix this is to use apt-get to reinstall the appropriate package: root@ubuntu# dpkg-query -S /var/spool/cron/crontabs cron: /var/spool/cron/crontabs root@ubuntu# apt-get install -...
crontab -e yields: /var/spool/cron/: mkstemp: Permission denied
1,450,463,937,000
I've been migrating my crontabs to systemd's timer units. They all look similar to this: .timer file: [Unit] Description=timer that uses myjob.service [Timer] OnCalendar=*-*-* *:00:00 Unit=myjob.service [Install] WantedBy=timers.target .service file: [Unit] Description=Script that runs myjob.sh [Service] ExecStart...
I resolved this problem by converting my 'user' timers into root/system timers. I disabled all of my .service and .timer files, and moved them out of my home directory into /etc/systemd/system. I added the 'User=' section to each service file, so that my scripts were ran by the regular user and not as root. Now my t...
Prevent systemd timer from running on startup
1,450,463,937,000
Say I'm running a C program via crontab -e: 15 11 * * * time /home/philip/school/a1_c_program.c > /home/philip/logs/time2execute.txt But the C program requires the user to enter some text. What happens in this situation? Does the C script just remain an open process on my machine until I restart? Or does it automatic...
Tools running by the cron daemon get an environment from the cron, and not from your shell. The cron doesn't provide a standard input for these tools, more exactly it provides a faked one from the /dev/null device. Thus, if the tool requires standard input, it will get an end-of-file error as it tries to read in the i...
What happens to cron-job that requires user prompt?
1,450,463,937,000
I want to set a cronjob entry that runs a script every 30 minutes from 9:00 to 18:00 but I do not want it to run at 18:30. The script should run for the first time at 9:00 and for the last time at 18:00. Is this possible?
0,30 9-18 * * * /path_to_script However, the above will run at 18:30. So, you're best bet is to have a separate job to handle 18:00. So: 0,30 9-17 * * * /path_to_script 0 18 * * * /path_to_script Also, Cron job generators are awesome.
Cronjob to run every 30 minutes
1,450,463,937,000
I am using vagrant boxes for several tests and in this particular case it is the Fedora 31 box from Bento with VirtualBox. When trying to use the crontab command, I get an error that it is not found. A quick search with locate tells me that there is no cron system installed at all. Is it a new default in Fedora 31 to ...
Per the Fedora Documentation, Fedora comes with the following automated task utilities: cron, anacron, at, and batch. However, it appears that these need to be installed as they do not come included: Installing Cron and Anacron To install Cron and Anacron, you need to install the cronie package with Cron and the cr...
Crontab command missing in Fedora 31
1,450,463,937,000
I have following crontab file - # /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do. SHELL=/bin/sh PATH=/...
Please notice that the file /etc/crontab has wrong permissions, that makes cron to ignore the file and not run the tasks inside of that file: Sep 18 11:15:22 dpiplserver cron[3164]: (system) INSECURE MODE (group/other writable) (/etc/crontab) Fix it using the command sudo chmod 600 /etc/crontab and restart the serv...
Cron does not print to syslog
1,450,463,937,000
In cron you can specify */n where n means every n times period, for instance in the first column is minute. */5 means every 5 minutes, but which minutes? 0, 5, 10, ...? What happens if the number specified is not a divisor of 60? */7 what will happen, will it start to skew in the next hour?
It'll go on 7, 14, ... 56, 0, 7, 14, ... With that syntax, I like to think of it as going when t mod x === 0
cron every X exact meaning
1,450,463,937,000
The acme-client(1) man page suggests the following cron entry: ~ * * * * acme-client example.com && \ rcctl reload httpd When I add to crontab the edit is not saved when I use that syntax: crontab: installing new crontab "/tmp/crontab.nOryzjBTlv":22: bad minute crontab: errors in crontab file, unable to...
There is no way to split a single command line onto multiple lines, like the shell's trailing "\" You'll find the above statement in the following paragraph if you do man 5 crontab. Please note below is from Ubuntu 20.04LTS. The ``sixth'' field (the rest of the line) specifies the command to be run. The entire com...
How come I can't use `\` to continue a line in crontab?
1,450,463,937,000
i have a query on cronjob , if i execute a command using cronjob is it possible to display the output in terminal rather than saving in output file . say for eg */2 * * * root /bin/ping xx.xx.xx.xx the output should display in the terminal . i tried it doesn't show in the terminal. Anything i need to change in my c...
You can't do this. All cron jobs are run in non-interactive shells, there is no terminal attachment. Hence the concept of /dev/tty or similar is not available in cron.
How to execute the command in cronjob to display the output in terminal
1,450,463,937,000
crond[2113] : (*system*) RELOAD (/etc/cron.d/mycron) My cron job is not working and I got the error above in log, What does mean that, how can I know what is going on. My cron job code: SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ * * * * * root php /var/www/html/app/checkUserAction.php
This is not an error. This is the cron daemon informing you that it has detected that /etc/cron.d/mycron was modified and loaded the new version of the file. Errors from the cron daemon itself will be in the same logs (probably, unless you've reconfigured logging). Errors from the job itself are sent as an email to ro...
what does mean crond[2113] : (*system*) RELOAD (/etc/cron.d/mycron)
1,450,463,937,000
I get this message when there is an error in my crontab: cron: No MTA installed, discarding output I don't want to install a MTA on my system, but I also don't want to miss these error messages. Where is it configured, that cron tries to send these by mail? Can I change that, so that these messages are send to a file...
I believe I have a solution, but it is only tested halfway. Unfortunately, I couldn't test /dev/xconsole, because I don't have that device on my systems, and I admit that I even don't know what it is and that I don't have the time to research it. However, there are two good things: First, the following method is gener...
cron: send error messages to file, when no MTA is installed
1,450,463,937,000
I have a script which dumps out database and uploads the SQL file to Swift. I've run into the issue where the script runs fine in terminal but fails in cron. A bit of debugging and I found that the /usr/local/bin/swift command is not found in the script. Here's my crontab entry: */2 * * * * . /etc/profile; bash /...
Cron doesn't run with the same environment as a user. If you do the following you will see what I mean: type env from your terminal prompt and make note of the output. Then set a cron job like this and compare it's output to the previous: */5 * * * * env > ~/output.txt You will find that the issue is likely because...
Script in cron cannot find command
1,450,463,937,000
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 using crontab but, after reading this answer, I am not sure if it is a good idea. Is it better to include shutdown -h 22:00...
The shutdown command has already an embedded scheduler so you don't need a cron job for it to run at the specified time. In Linux as everywhere else, it's better to stick to the KISS principle (Keep It Short and Simple). shutdown -h 22:00 will work fine, no need to run it in the background. Add the command at the en...
How to schedule shutdown every day?
1,450,463,937,000
*/n * * * * in a crontab means run every n minutes, if n divides 60 evenly. What happens for other cases, like */13 * * * *?
'*' is equivalent to the full range of possible values, in this case '0-59' '/13' represents the "step size" or increment used to determine the next run, starting with the initial possible value. (e.g. "Every 13 minutes starting at 0") When the minutes get reset (59 to 0) it starts over. So for example */13 will alw...
What does */13 do in a crontab?
1,450,463,937,000
I've been using kSar to look at my servers resource use. There is a definite spike in process creation at 4:04AM daily. Cron seems to define the interval they should be run, but not the specific time How can I find what cron job runs at that time?
If you look at any CentOS 5 or 6 system the file /etc/crontab is typically where all the action starts. There are 4 directories that will contain various scripts. These directories are named: $ ls -1d /etc/cron* /etc/cron.d /etc/cron.daily /etc/cron.deny /etc/cron.hourly /etc/cron.monthly /etc/crontab /etc/cron.weekly...
How to find a cron job if you know the specific time it runs?
1,450,463,937,000
I want to have a script running in screen at startup. This doesn't work: @reboot pi screen -d -m /home/pi/db_update.py however running this manually as user pi works: screen -d -m /home/pi/db_update.py Any idea on what I am missing?
Instead of adding @reboot pi ... to /etc/crontab you should run crontab -e as user pi and add: @reboot /usr/bin/screen -d -m /home/pi/db_update.py Make sure to use the full path to screen (just to be sure, it works without it), and that the /home/pi is not on an encrypted filesystem (been there, done that). The comma...
Running `screen` through a @reboot cron job
1,450,463,937,000
I am trying to get ssh to work in cron, and it seems like I have tried all the standard tricks with no luck at all. I can run a non-interactive ssh by using >./some_script_with_ssh in bash. It's only when I try to use it in cron that it fails. Any help I could get would be greatly appreciated. Below are some of the ...
debug1: Offering RSA public key: /home/zach/.ssh/id_rsa debug3: send_pubkey_test debug3: send packet: type 50 debug2: we sent a publickey packet, wait for reply debug3: receive packet: type 60 debug1: Server accepts key: pkalg ssh-rsa blen 279 debug2: input_userauth_pk_ok: fp SHA256:jsePXa9FO8c9f0bVwdgvXMJQ2GyHVqz5spa...
SSH with Cron: RSA key not accepted
1,450,463,937,000
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(8) Says /etc/cron.d/: directory that contains system cronjobs stored for different users. What does "stored for diff...
/etc/crontab is the historical location for "system" jobs. It's not necessarily used on all systems (eg RedHat 7 and derivatives has an "empty" entry), or it may have commands to call out to cron.daily and others. /etc/cron.d/* is, essentially, the same as /etc/crontab but split out into separate files. This makes i...
Differences between `/etc/crontab`, files under `/etc/cron.d/` and `/var/spool/cron/crontabs/root`?
1,450,463,937,000
I have a bash script that is run nightly in a cron job. It needs to do case insensitive file matching, so the script calls shopt -s nocaseglob I want to make sure this does not affect other cron scripts. Does this setting persist after this one script ends? Or is this setting enabled only for the duration of the scri...
Setting options with shopt is a shell setting. It only affects the shell instance that you run it in: it is local to the shell process and to subshells invoked by $(…), (…) and similar constructs. It has no effect on other shell scripts executed concurrently or later, nor even on independent bash scripts that happen t...
Scope of shopt options in cron script
1,450,463,937,000
If I schedule something with 'at` like, $ at noon warning: commands will be executed using /bin/sh at> echo "Will I be created?" > /tmp/at_test at> <EOT> job 12 at Fri Jun 30 12:00:00 2017 And if I reboot the machine before execution time, will my command be executed? Unlike regular cron which schedules tasks from f...
Jobs are stored in /var/spool/cron/atjobs in Ubuntu for instance. Jobs are a file with some environment variable set (like $PATH, current working directory). The host can be rebooted, if the host is up, jobs will start. man at should tell you more about it. Note that some Unices have special cron entry like @reboot.
Will 'at' command be executed after the reboot? [duplicate]
1,450,463,937,000
Is there a preferably CLI based program I can use to regularly (through cron for example) use to check a mailbox, and download the attachments into a folder? I have a mailbox called [email protected], I would like to periodically poll the inbox for new emails via POP or IMAP, and grab the attachments to any new emails...
Fetchmail is the de facto standard program to retrieve mail over POP or IMAP automatically. You can inject email in the local email system for delivery, or have fetchmail invoke a mail delivery agent such as procmail or maildrop directly. To extract and possibly strip the attachments, you can use any of the several MI...
Periodically download attachments from mail box
1,450,463,937,000
I have cloned a Git repository of some project. I want to automate git pull and compile the project once in a week. I am using a laptop which won't be on 24x7. Now, I cannot use cron as I should keep the system running at that exact moment. I cannot use anacron either, as it might start before I connect to network. I...
Run the job when you connect to the network. Most distributions have a scripting infrastructure that you can plug into, though you will need root permissions. If you connect with NetworkManager or Wicd, they have their own hook infrastructure as well. Add a cron job that only runs if the network is available (and, opt...
How to schedule a job that depends on network availability?
1,450,463,937,000
I have a problem with a user's crontab. Crontab refuses to run any job unless it's scheduled to run every minute (* * * * *). An soon as you edit the task to run, say, on minute 15 of every hour, it fails to run. This runs ok every minute: * * * * * touch /tmp/test01 This fails to run on minute 15 of every hour. It ...
I can't give you a specific answer, but here is how i would go about troubleshooting this: Try more combinations to find another working expression. How about: */2 * * * * (every other minute), or * */2 * * * (every minute, every other hour). It would be interesting to establish that any relative expression works wh...
My crontab only likes five asterisks (timezone related?)
1,450,463,937,000
I need to run my application in screen when specific users are logged out and kill the screen when someone from my user list logged in. So I am thinking about bash script, which will be called periodically from cron and: Checks if specific users are logged in. If nobody is logged in - spawn screen and save pid to fil...
Several obvious options: modify /etc/profile to add a logout hook (or if your system already has a logout hook file, modify that) modify the system PAM configuration to add an extra session controller (pam_script library specifically addresses this) modify the login shell of the users under consideration to something...
Run script when specific users logout
1,431,818,419,000
I've started using sudoedit <file> instead of sudo vim <file>. One of the advantages is that it uses my local ~/.vimrc. However, when using sudo crontab -e, it uses /root/.vimrc instead. Is there a way to make sudo crontab -e use my local ~/.vimrc? Here is a related question, about using sudoedit with vimdiff. However...
Assuming that you want to be editing root's crontab, sudo must give you root authority. After it does so, crontab will invoke ${VISUAL:-${EDITOR:-vi}} (it'll use $VISUAL unless it doesn't exist; in that case it'll use $EDITOR unless it doesn't exist; in that case it'll use vi). You have a few possible solutions. The...
How can I make `sudo crontab -e` use my `sudoedit` environment?
1,431,818,419,000
For a while now, I have had the problem that a gzip process randomly starts on my Kubuntu system, uses up quite a bit of resources and causes my notebook fan to go crazy. The process shows up as gzip -c --rsyncable --best in htop and runs for quite a long time. I have no clue what is causing this, the system is a Kubu...
Process tree While the process is running try to use ps with the f option to see the process hierarchy: ps axuf Then you should get a tree of processes, meaning you should see what the parent process of the gzip is. If gzip is a direct descendant of init then probably its parent has exited already, as it's very unli...
A gzip process regularly runs on my system, how do I figure out what is triggering it?
1,431,818,419,000
It's simple enough to use cron to schedule a job to occur periodically. I'd like to have something occur less regularly -- say, run the job, then wait 2 to 12 hours before trying again. (Any reasonable type of randomness would work here.) Is there a good way to do this?
You could use the command 'at' at now +4 hours -f commandfile Or at now +$((($RANDOM % 10)+2)) hours -f commandfile
Schedule job at irregular intervals
1,431,818,419,000
I'm trying execute a basic shutdown crontab to run M-F at 10PM. So I did the following: sudo crontab -e Once inside of the crontab I added the following line: 0 22 * * 1-5 shutdown now The job doesn't seem to be running properly and I cannot find any errors in /var/log/syslog. Is there anything glaringly wrong her...
Your problem is probably that the PATH in your crontab file is limited and does not include /sbin where shutdown is most likely located. You should therefore use the full path for shutdown (you can check that with sudo which shutdown ): 0 22 * * 1-5 /sbin/shutdown now From man 5 crontab: Note in particular that if...
Crontab not working
1,431,818,419,000
I'm am using servers (debian 7) and I'm currently running cron-apt to e-mail me when there are new upgrades available. Is the following command safe to run when new upgrades are shown? sudo apt-get dist-upgrade Are there any checks I should do before upgrading? I'm a little concerned that simply upgrading everythin...
sudo apt-get dist-upgrade is very safe to run as it won't do anything to the system, instead stopping to ask for your confirmation ;) You would have to add a -y switch, which is intended for unattended upgrades and makes apt assume that you always answer 'yes' to questions: sudo apt-get -y dist-upgrade. The man page s...
Upgrading packages automatically
1,431,818,419,000
I want to schedule my script for last Saturday of every month. I have come up with the below: 45 23 22-28 * * test $(date +\%u) -eq 6 && echo "4th Saturday" && sh /folder/script.sh Is this correct or I need to change it? I can't test it right now as it will be invoked only on last saturday. Please advise. I have ...
Your logic will not work. Month can have last Saturday to be on 29 or 30 or 31. For this reason the best way to do the check is to run it every Saturday and check in script if this is in last 7 days in month: 45 23 * * 6 sh /folder/script.sh and add in your script (here assuming the GNU implementation of date) som...
Cron entry for last Saturday of every month
1,431,818,419,000
we want to delete all files of the following job with the same time on midnight 0 0 * * * root [[ -d /var/log/ambari-metrics-collector ]] && find /var/log/ambari-metrics-collector -type f -mtime +10 -regex '.*\.log.*[0-9]$' -delete 0 0 * * * root [[ -d /var/log/kO ]] && find /var/log/Ko -type f -mtime +10 -re...
Yes, it is perfectly acceptable to have cron schedule multiple jobs at the same time. Computers do nothing simultaneously, however, and they will be started in the order present in the cron table. However, they will not be run in sequence; they will be started one after the other within a few milliseconds of midnight...
is it ok to run cron job with the same time?
1,431,818,419,000
I was trying to automate some auto cleaning of my Ubuntu System, with Cron Jobs I tryed to simplify this: sudo find /var/log -type f -name "*.1.gz" -delete sudo find /var/log -type f -name "*.2.gz" -delete sudo find /var/log -type f -name "*.3.gz" -delete sudo find /var/log -type f -name "*.4.gz" -delete ,etc... into...
No need to use a for-loop here, you can just use find: sudo find /var/log/ -type f -regex '.*\.[0-9]+\.gz$' -delete However, as it was suggested, check the manual page of logrotate for ways to reduce the number of files.
command to clean up old log files
1,431,818,419,000
We're setting up an SGE cluster with CentOS 6. My sysadmin is installing applications that are not installed via RPM (i.e. via other means like make install) should go in a non-standard directory, in this case something like /share/apps/install/bin/. The path for this is currently added to most sessions (login, qlog...
What we ended up doing was a multi-pronged solution to avoid any path issues. Depending on the use case, we used one or more of the following: Used absolute paths to the binaries installed in non-standard places instead of expecting the binary to be on the path. This was used for tools that have few, if any, non-s...
Globally change path for all users, even in cron
1,431,818,419,000
I'm trying to write a very basic cron job but it doesn't seem to be saving. Here's what I've done: 1) crontab -e This opens up a file with vim. 2) #!usr/bin/env python 0 23 * * 0 ~/Desktop/SquashScraper/helpfulFunctions.py 3) :wq 4) crontab -l Nothing shows up and I get this message: crontab: no crontab for ben ...
For some reason /usr/bin/vi is not working correctly on your machine as you can tell from the error message: crontab: "/usr/bin/vi" exited with status 1 What happened there is that when you leave vi it is producing an error code. When crontab sees that vi exited with an error code, it will not trust the contents of t...
Cron job not saving
1,431,818,419,000
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?
No, cron scripts run parallelly, if you do not implement some locking mechanism. See Quick-and-dirty way to ensure only one instance of a shell script is running at a time and Correct locking in shell scripts? for possible solutions. A simpler way is to use lockfile, like in this answer or the run-one package (see ...
Can a crontab job run concurrently with itself?
1,431,818,419,000
Is it a good idea to create a cron job for apt-get update; apt-get upgrade for my webserver? So not apt-get dist-upgrade.
Yes, to a limited extent. But you don't have to. There's a package called unattended-upgrades that will do it for you. Description-en: automatic installation of security upgrades This package can download and install security upgrades automatically and unattended, taking care to only install packages from the confi...
Is it safe to set a cron job for apt-get upgrade? [closed]
1,431,818,419,000
Problem: When running the ssh-keyscan command in cron it emails me the output of ssh-keyscan every day. The email simply contains the following. # <hostname> SSH-2.0-OpenSSH_5.3 My (simplified) cron job: host=`uname -n` SSHKey=`ssh-keyscan $host` echo $SSHKey >> /root/.ssh/known_hosts My question: How do I preven...
redirect stderr into /dev/null host=`uname -n` SSHKey=`ssh-keyscan $host 2> /dev/null` echo $SSHKey >> /root/.ssh/known_hosts
Prevent ssh-keyscan from generating output
1,431,818,419,000
I'm relatively new to Linux and I'm working on a CronTab for scheduled backups. I figured out how to do multiple sequential jobs with ; and &&, but I'm unsure how the dependency affects the sequence. My cron job looks like this: # Every day at 0:00 (reboot server and do the hourly backup procedure). 0 0 * * * sh shutd...
Why don't you test it with some dummy commands that you know will work or fail? $ ls foo && echo ok1 ; echo ok2 ls: cannot access foo: No such file or directory ok2 $ ls foo && (echo ok1 ; echo ok2) ls: cannot access foo: No such file or directory So it seems like your intuition was correct, and you need the second ...
Execution order with multiple commands
1,431,818,419,000
On our linux server we have a lot of entries. Many entries look like this: 15 13 * * 3 /very/long/path/to/binary/run.sh ... These entries would be easier to maintain if I could write: 15 13 * * 3 $FPATH/run.sh Where could I write this mapping: FPATH=/very/long/path/to/binary
This perfectly works, ie $ crontab -l TESTDIR=/home/user/test * * * * * "$TESTDIR"/script.sh Have a look at man 5 crontab more info is found there.
variables in crontab
1,431,818,419,000
In macOS, cronjobs configured with crontab have the command output and/or error messages (if the cron doesn't succeed) written to the /var/mail/$USER file. Can this be prevented? I've tried: * * * * * /sbin/ping -c1 website.com ... 2>&1 >/dev/null Whether it succeeds or fails to reach the domain, the ping output...
The cron daemon does not write to /var/mail/$USER, it sends an email to the user whenever a job outputs anything or fails, which in turn is written to that file (the user's mail inbox) by the system's mail delivery service. To turn off the sending of email from the cron daemon, set the MAILTO variable to an empty valu...
Prevent cronjob's from writing to /var/mail/$USER?
1,431,818,419,000
First of all, I'm using elementary OS (based on Ubuntu 12.04). I have a cron job set up to run a script every day at 23:30: 30 23 * * * /path_to_script/ Is there a way to add it to cron via a single terminal command? All examples I've seen involve invoking cron first via crontab -e and then adding the job there. I'd...
You can do it with this: { crontab -l; echo "30 23 * * * /path_to/script/"; } | crontab -
Add cron job via single command [duplicate]
1,431,818,419,000
All of a sudden my cron jobs don't work any more. When I type crontab -e I am presented an empty file in the editor /tmp/crontab.3fMYGi/crontab And by empty I mean that not even this standard cron job info is there any more. Is there a way to recover my cron jobs?
As @Anthon said in comments, you most likely have lost your crontab entries. On the off chance you haven't, they would be located here in this directory: /var/spool/cron/ in a file named after your username. If they aren't there either then they're lost and you'll have to recreate them or get them from backups. You mi...
Suddenly lost all cronjobs
1,431,818,419,000
0 0 * * 1 root hostname >> /tmp/hostname.txt The above cron entry should run midnight on monday and create a file in /tmp called hostname.txt with the output of the hostname command. But it is just a blank file that is created. Why?
When dealing with crontab entries it's important to make the distinction between a system level cron, typically in one of these locations: /etc/crontab /etc/cron.d/* /etc/cron.daily/* /etc/cron.weekly/* etc. Or the user level variety, that are actually stored in this directory, /var/spool/cron: $ sudo ls -l /var/spo...
why doesn't 0 0 * * 1 root hostname >> /tmp/hostname.txt work as a crontab?
1,431,818,419,000
I have a cron job on Debian: 1 * * * * /home/paradroid/bin/myscript.sh >/dev/null There is an installed and configured MTA, and I have received emails when the script has a syntax error, so I have always thought that I would be informed when anything goes wrong. The script downloads a file using curl through a proxy....
After talking to some people on #curl on Freenode, a dev mentioned that there has been a bug in curl for around a decade (before 7.23.0) where an option parsing error treated -Ss (--show-silent --show-error) as -s (--silent), so all output is suppressed, including stdout. The solution (before 7.23.0) is to use -sS ins...
Crontab job not emailing on failure
1,431,818,419,000
I'm using Devuan ASCII (which is more or less Debian 9, Stretch). Now, my /var/log/auth.log has a bunch of these entries: Jan 6 09:45:01 mybox CRON[20951]: pam_env(cron:session): Unable to open env file: /etc/environment: No such file or directory Jan 6 09:45:01 mybox CRON[20951]: pam_unix(cron:session): session ope...
Answering all of your questions Why is cron/pam_env/pam_unix trying to open that file in the first place? See BUG #646015. In some cases (like locale related stuff) this file is deprecated. But it is still used system-wide, and log is made whenever it is missing. If they legitimately expect it, why isn't it ther...
Cron is trying (and failing) to open env file: /etc/environment
1,431,818,419,000
My script (status.sh) is: #!/bin/bash SITE=http://www.example.org/ STATUS=$(/usr/bin/curl -s -o /dev/null -I -w "%{http_code}" $SITE) if [ $STATUS -eq 200 ] then echo $STATUS >> /home/myuser/mysite-up.log else echo $STATUS >> /home/myuser/mysite-down.log fi I run: $ chmod +x /home/myuser/status.sh Then on my cro...
The main difference between running a script on the command line and running it from cron is the environment. If you get different behavior, check if that behavior might be due to environment variables. Cron jobs run with only a few variables set, and those not necessarily to the same value as in a logged-in session (...
Script with curl works manually but not in cron job
1,431,818,419,000
I am running Raspbian on a Pi and installed cron to schedule a job. I wrote a Python script and I set it to run every 5 minutes. The job is happening every 5 minutes, no problems, but when I run crontab -l as root and pi, it says there are no jobs. When I run crontab -e as root and as pi they are blank. I honestly can...
There are two lists of scheduled tasks (crontabs). Each user (including root) has a per-user crontab which they can list with crontab -l and edit with crontab -e. The usual Linux implementation of cron stores these files in /var/spool/cron/crontabs. You shouldn't modify these files directly (run crontab -e as the user...
Cron job working, but crontab -l says no jobs
1,431,818,419,000
I have several cron jobs that are executed every minute, and I’m thinking on putting @reboot jobs. They are put and executed with root privileges. So here’s what I want to know. Will these cron jobs run when system gets to the login screen after rebooting? Will @reboot entries run after reboot without me getting logge...
The cron daemon will start cron jobs scheduled with @reboot as soon as the daemon has started after system boot. It does not matter whether any user has had the time to log in on the newly rebooted system or not or whether the job belongs to the root user or any other user on the system. It is likely that such jobs w...
When is a @reboot cron job executed?
1,431,818,419,000
I have a shell script which runs in cronjob. This shell script has to kill a process which is running and start the new process again. When I run the script manually it works perfectly fine, but when it runs through cron it does not kill the old process but starts a new process along with the old one. I am using the b...
You have to indicate what to kill: kill -9 $(ps | grep "server1" | grep -v grep | awk '{ print $1 }') You can also use the trick: kill -9 $(ps | grep "server[1]" | awk '{ print $1 }')
How to kill a process in shell script which is running through cron?
1,431,818,419,000
Is it possible to switch the current tty/vt with the help of a bash script or a cronjob? I only know the physical keyboard input "Ctrl-Alt-Fx". I would like to show two virtual desktops at different daytimes (controlled by cron).
Yes, that is possible. You're looking for the chvt command.
How to switch tty with a script / cronjob
1,431,818,419,000
Problem statement I have 5 solaris boxes, some have Solaris 10 and some have Solaris 9. All of them have many cronjobs in their crontabs. I would like to know number of active cronjobs available, so I manually count the cronjobs. Now I am looking for a command [bash shell I am using] to count the number of active cron...
You need to delete everything that does not start with a digit (the minute). But to get that, remove any leading whitespace first. This will get rid of comments, blank lines, variable assignments, etc. crontab -l 2>/dev/null | sed 's/^ *//;/^[*@0-9]/!d' | wc -l
command for counting number of active cron jobs in crontabs