date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,431,818,419,000 |
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 command itself, in case it helps, (arrows indicate line-wrapping for legibility) is:
/usr/bin/php -C /etc /path/to/process.p... |
I've found the problem. The -C command line switch I'm sending to php, which should have been -c. I've no idea why cron wasn't reporting that to me in any manner, let alone a useful manner (or how I somehow managed to get it into the crontab with a capital C but test it on the CLI with a lowercase), but running it yet... | Frustrating issue where neither cron nor su -c runs my job (permissions?) |
1,431,818,419,000 |
Let's assume that I want to run a shell script named test.sh at 1 AM every day. I could either use:
0 1 * * * /home/user/test.sh
Or I could use:
0 01 * * * /home/user/test.sh
For the above example, which is technically the correct answer - should a leading 0 be used in the shedule, or should just the number of the h... |
If your cron accepts zero-filled numbers, you may use them.
Since the POSIX specification for crontab and the crontab(5) manual on all systems that I have access to only give examples without zero-filled numbers (without actually saying anything about the formatting of numbers), it may be prudent to stay with non-fill... | When scheduling jobs to be run by crontab, should leading zeros be used for the hour? |
1,431,818,419,000 |
I'm looking for how to automatically backup a user's home directory in CentOs 7 to a remote host or NAS or just to ~/.snapshot. In some Linux setups, I have seen a .snapshot folder in the user's home directory (~/.snapshot/) that holds hourly, nightly, and weekly backups of their home directory (ie ~/.snapshot/weekly1... |
How about this guide:
create your script: create new file and call it myrsync.sh, copy/paste the lines below:
#!/bin/bash
sudo rsync -av --progress --delete --log-file=/home/your-username/Desktop/$(date +%Y%m%d)rsync.log --exclude "/home/your-username/.folder" /home/data /media/dataBackup$(date +%Y%m%d_%T)
Meaning ... | Scheduled folder backup |
1,431,818,419,000 |
I'm thinking about setting up a cronjob for fetching all my repositories every once in a while, to have the current status ready in case I'm offline. Something like the following (wrapped for better readability):
find $HOME -name .git -type d -printf "%h\0" |
parallel --gnu -0 --delay 0.2 --jobs 100 --progress \
'... |
I've been fetching my local Git repos in the background for two years now, without any sign of trouble. Currently, crontab contains something like
savelog -n -c 400 ~/log/git-fetch.log
find ~/git -type d -execdir [ -d '{}/.git' ] \; -print -prune |
parallel --gnu --keep-order \
"date; echo {}; cd {}; git fetc... | Fetching all Git repositories in the background |
1,431,818,419,000 |
Both the shell and environment variables that cronjobs are run in is completely different from the ones presented to me in gnome-terminal. How can I run a cronjob under the same circumstances as if I had run it in the terminal?
My current solution is running the cronjob env DISPLAY=:0.0 gnome-terminal -e my-command, b... |
You can either explicitly specify the environment variables you want at the top of your crontab, or you can source your environment from somewhere.
To add environment variables explicitly, you can use a line like this at the top of your script (after the hashbang):
FOO=bar
To source them from a file, use a line like ... | How to run a cronjob in my regular environment? |
1,431,818,419,000 |
I have a python script that I need to run from crontab routing all traffic via a HTTP proxy.
I have already set the proxy in /etc/profile using
http_proxy=http://192.168.0.1:3128 # (Address changed for privacy)
https_proxy=http://192.168.0.1:3128
export http_proxy
export https_proxy
Of course this works fine if I... |
That second example looks like the right thing to do, but you should change the variable names to lower-case, as the HTTP libraries expect.
The manual page for the crontab file format (i.e. crontab(5) - not crontab(1)) says:
An active line in a crontab will be either an environment setting or a cron command. The cr... | How should I set HTTP proxy variable for cron jobs? |
1,431,818,419,000 |
I have a server in which there are about a 100 Cron jobs that run various PHP scripts. The task at hand is to generate an alert any time an error occurs in the execution of a PHP script.
The Crons are set as follows:
30 08 * * * /usr/bin/php /var/www/html/phpscirpt1.php > /var/www/html/phpscript1.log 2>&1
What I ... |
Basically your solution is good. You have just made simple bash syntax error.
You have to put spaces around '[' and ']' characters:
[ $? == 1 ]
I've tested it on my box and it works. I would also suggest to test error code as not equal 0 ([ $? -ne 0 ]), unless you are sure that you want to react only on error code 1.... | Using an If Statement in Crontab To Generate an Alert |
1,462,031,588,000 |
I am trying to build a Debian-based image to dockerize a cron process, but my cron jobs are never started.
Here is my Dockerfile:
FROM debian:jessie
RUN apt-get update && apt-get install -y --no-install-recommends cron
COPY jobs.txt /etc/crontab
RUN touch /log.txt
CMD ["cron", "-f"]
...and the jobs.txt file:
* * * * ... |
The only difference between using COPY and RUN are the permissions on the /etc/crontab file: with COPY this is 664 and with RUN 644.
I cannot find anything on permissions that /etc/crontab needs to have but if you add
RUN chmod 644 /etc/crontab
after the COPY line in your Dockerfile the cronjobs run (at least for m... | How to build a cron docker image properly? |
1,462,031,588,000 |
using linux. I know you can do an @reboot cronjob. I want to do an equivalent thing but instead of running at reboot, running after my computer awakens from suspend. Is that possible?
|
Depends on your distro and/or your destop enviroment, without this info i cant tel much, only that each dispo/desktop enviroment handle it on other ways.
like you see the way for ubuntu is nearly complete different how debian handle this.
Ubuntu solution https://askubuntu.com/questions/226278/run-script-on-wakeup
Debi... | cronjob at resume from suspend |
1,462,031,588,000 |
If it exists, what is the maximum number of cron jobs (entries?) that can be added to a server's crontab? How do I tell? I'm on RHEL 6.
I googled around, but did not see a conclusive answer -- some were 256, some 65K, some said limitless.
|
To answer your question you should have a look at the cron implementation for your distribution. RHEL seems to use cronie - you can find the source code for cronie online.
cronies limit seems to depend on the filesystem (maximum file size) as the cron daemon stores the crontab entries per user in a linked list - see u... | Maximum Number of Entries in Crontab |
1,462,031,588,000 |
Is there some way to display a list of the approaching task executions? That is, translate this crontab:
# m h dom mon dow command
* * * * * imapfilter
4 20 * * Sun fgit gc -- ~/*/ ~/.*/ ~/dev/*/
into this:
2012-04-12 14:40 imapfilter
2012-04-12 14:41 imapfilter
...
2012-04-15 20:03 imapfilter
2... |
I liked the idea, so I did it. It can be downloaded from here.
| How to print the next crontab tasks to be executed? |
1,462,031,588,000 |
I am unable to configure a cron job to run by placing it in /etc/cron.hourly folder.
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-par... |
In order to isolate the problem, move /usr/local/xxxx/check-interface.bash to /etc/cron.hourly/check , and then see if it runs.
If the script does run, then the problem is caused by an ownership/permissions or related issue which is preventing cron from executing scripts at /usr/local/xxxx/*.
If the script does not ru... | Configuring cron.hourly |
1,462,031,588,000 |
When I schedule a job/command with at to be executed in the future, the standard output and error of the command is "mailed" to the user that did the scheduling.
So after my job runs, I get a message in the command prompt
You have mail in /var/spool/mail/mattb
which I can then read with mail.
Is it possible to have... |
at will typically use your installed mail transport agent (MTA) to deliver the mail. If you do not use local mail on the box at all, you can configure your MTA to forward all mail to another server.
Alternatively you can use a .forward file for a single user. If you put "[email protected]" in ~mattb/.forward then your... | When I schedule a command with 'at', can I change where the output is mailed to? |
1,462,031,588,000 |
I installed the yum-cron package, configured too only check for updates and then mail me. But, doing this daily, seems a bit too much. I would like to do this monthly.
The file is located in /etc/cron.daily/0yum-cron, I want to move it to /etc/cron.monthly/0yum-cron. Can I do this, or is this a big no-no when using yu... |
If you want to move it from daily to monthly run, you need to use mv and not cp as otherwise you would simply add a monthly run.
sudo mv /etc/cron.daily/0yum-cron /etc/cron.monthly/0yum-cron should do what you're asking for.
| Can I move 0yum-cron from cron.daily to monthly? |
1,462,031,588,000 |
I have written a simple shell script to backup the tables in my DB using the mysqldump command. The command simply dumps the DB into a dbName.sql file. However, if the dbName.sql file doesn't already exists and I crontab this shell script, it doesn't work. What could be the reason? Are crontab scripts not permitted to... |
Cron jobs can be run as root or another specified user. If that user does not have the permission to write to the .sql file the job will fail.
If the file exist and it has write permission for the user running the job the file will be written.
if the file does not exist and the user does not have permission to create ... | Crontabbed shell script not able to create/write to a file |
1,462,031,588,000 |
Recently I started the process of gradual switching my shell to nu
and because of it I thought about assigning its path to SHELL in cron.
Having read a good part of the manual at man 5 crontab, I took a look at PATH and copied the convention of using : in between the values attempting to assign two shells to SHELL:
SH... |
No, having multiple shells in SHELL doesn't make sense, for the reasons @Stephen described in their answer. But, the SHELL variable only controls the shell cron uses to run the immediate command part in the crontab line; and at least in Vixie cron, which you often have on Linux systems, SHELL can be changed in the mid... | Can it possibly work if I assign two shells to SHELL in cron? |
1,462,031,588,000 |
I would like to disable the ssh server for certain times of the day. I would like to do this because I recently experienced a brute force compromise via ssh. Can crontab be used to enable/disable SSH?
If not, is there another way to disable ssh at certain times of the day?
|
Sure, just run whatever init scripts there are to stop and start ssh daemon (e.g. /etc/init.d/ssh stop and /etc/init.d/ssh start) at appropriate times.
However, I'd suggest looking into fail2ban, portknocking, disabling password authentication and using only ssh keys, and the most secure way, two factor authentication... | Is it possible to enable/disable SSH using cron |
1,462,031,588,000 |
I am trying to figure out why I don't have syntax highlighting when editing my crontab.
I have both $EDITOR and $VISUAL set to /usr/bin/vim:
> echo $EDITOR
/usr/bin/vim
> echo $VISUAL
/usr/bin/vim
If I save the crontab to a file and edit it with vim syntax highlighting is enabled.
> crontab -l > saved_cronab
> /usr/b... |
Did you export these variables (export EDITOR VISUAL)?
| No syntax highlighting when editing crontab |
1,462,031,588,000 |
On all my Red Hat Linux machines version 7.2 we saw that systemd-tmpfiles-clean.service is inactive:
systemctl status systemd-tmpfiles-clean.service
● systemd-tmpfiles-clean.service - Cleanup of Temporary Directories
Loaded: loaded (/usr/lib/systemd/system/systemd-tmpfiles-clean.service; static; vendor preset: disa... |
You can ask systemd what a unit’s triggers are:
systemctl show -p TriggeredBy systemd-tmpfiles-clean
This will show that the systemd-tmpfiles-clean service is triggered by the systemd-tmpfiles-clean.timer timer. That is defined as
# SPDX-License-Identifier: LGPL-2.1+
#
# This file is part of systemd.
#
# systemd i... | Linux + files & folders cleanup under /tmp |
1,462,031,588,000 |
I have a setup in which I sync files between two Linux servers using Unison over an SSH connection. This is implemented by running the following command via cron:
unison -auto -batch PROFILE
Changes to the fileset happen almost exclusively on one side (the other system is an off-site replica). They mostly take place ... |
Reasons I am running Unison as a cron job rather than with -repeat (presumably as a systemd service)
I would actually suggest that systemd is a perfect fit for when you want "cron but single instance". You don't need to keep it as a long-running service - you can use systemd timers in a cron-like manner while taking... | Unison via cron, how to deal with one job still running as the next one starts |
1,462,031,588,000 |
How can I send a CTRL+C to my tmux tab using crontab? I have the following and it works for sending commands, but I'm not sure how to send a CTRL+C to it.
0,30 * * * * /usr/bin/tmux send-keys -t 0 "CTRL+C"
|
Ctrl keys may be prefixed with C- or ^
(source)
0,30 * * * * /usr/bin/tmux send-keys -t 0 C-c
| How to send a CTRL+C to a tmux pane using crontab? |
1,462,031,588,000 |
I have a bunch of devices all running a similar cron job. Currently I'm setting a cron minute and hours to a random number (that way they don't all run at once).
$random_minute $random_hour * * * sudo /bin/script
I want to keep this pattern of making each device random but I also have a script which needs to be run e... |
There aren't that many hours in the day, so why not just
17 3,9,15,21 * * * sudo /bin/script
to run at 03:17 and every 6 hours hence?
The alternatives would involve adding a sleep to the program itself:
0 */6 * * * (sleep 11820; sudo /bin/script)
or running the script more often (say, hourly), and having the script ... | Cron */6 hours but with an offset? |
1,462,031,588,000 |
I am using Ubuntu 14.04. I wrote a small script named trial. The contents of the script are as follows:
#!/bin/sh
SHELL=/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
sh -c firefox
I copied the script to /etc/init.d, modified permission using chmod +x trial and used update-rc.d trial defaults. The file made link bu... |
The directory, /etc/init.d/ contains system scripts that essentially start, stop, restart daemons (system services). It's the "System V Initialization" method (SysVinit), containing the init program (the first process that is run when the kernel has finished loading). (EDIT 2 July 2015: Many Linux systems have recentl... | Run a GUI program at startup |
1,462,031,588,000 |
I need a bash script (not sure how to write the actual .sh file) which I could set to be run by cron every minute and that would delete files with the name index.html that are in a specific directory and its subdirectories.
I believe that the following command will do that. However, I need to write it as a script file... |
I wouldn't even write the script -- you should be able to put the find command in directly. You can also call the delete command directly from find using the -delete action flag.
Step 1: edit crontab
crontab -e
Step 2: add in the following line (this will run it daily at 4:30am, change to your liking):
30 4 * * * fin... | Bash script to delete a file called index.html recursively |
1,462,031,588,000 |
Is it just for controlling the permissions of the script being called or does it also effect when or if the script runs? I assume if I setup a cron for a non-root user it should always run, even if I haven't logged in as that user since reboot, right?
|
Remember that Unix was originally designed as a multi-user system, where multiple people were using the same physical computer. (Unlike today, where most Unix systems are used by only one person, and multiple user accounts are just to limit vulnerabilities.)
So the original reason for per-user crontabs was so that ea... | What's the purpose of having different crontabs per user? |
1,462,031,588,000 |
In the ~ directory of the root user on my debian wheezy server regularly appears file named dead.letter with (currently) the following content:
orion : Jul 25 10:17:31 : root : unable to resolve host orion
orion : Jul 26 02:17:18 : root : unable to resolve host orion
orion : Jul 26 21:17:19 : root : unable to resolv... |
Change the following line in /etc/hosts
127.0.0.1 localhost
to
127.0.0.1 localhost orion
Your MTA was unable to resolve the domain name of your machine.
| Mysterious "unable to resolve host" in dead.letter |
1,462,031,588,000 |
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 knowledge.
Basically I have two php scripts that reside in a directory on my server. For the purposes of the applicati... |
I'd like to expand on Davidann's answer since you are new to the concept of a cron job. Every UNIX or Linux system has a crontab stored somewhere. The crontab is a plain text file. Consider the following: (From the Gentoo Wiki on Cron)
#Mins Hours Days Months Day of the week
10 3 1 1 * ... | Cron job to check if PHP script is running, if not then run |
1,462,031,588,000 |
I've created new system account for cronjob on my centos 7 and set up a cronjob for it.
However my cronjob fails to run with error:
(CRON) ERROR chdir failed (/home/sysagent): No such file or directory
Currently crontab for sysagent account looks like:
15 16 * * * HOME="/tmp" && cd path/to/project_folder && ./src/main... |
On the assumption the docs are bad or wrong, a source code dive:
% rpm -qa | grep cron
cronie-1.4.11-17.el7.x86_64
cronie-anacron-1.4.11-17.el7.x86_64
crontabs-1.11-6.20121102git.el7.noarch
... some altagoobingleduckgoing here as the URL in the RPM is broken ...
% git clone https://github.com/cronie-crond/cronie && c... | Why cron trying to change to user's home directory and how to avoid this? |
1,462,031,588,000 |
In the process of learning/understanding Linux (difficult but enjoying it). I have written a very short shell script that uses wget to pull an index.html file from a website.
#!/bin/bash
#Script to wget website mywebsite and put it in /home/pi/bin
index=$(wget www.mywebsite.com)
And this works when i enter the com... |
This line index=$(wget www.mywebsite.com) will set the variable $index to nothing. This is because (by default) wget doesn't write anything to stdout so there's nothing to put into the variable.
What wget does do is to write a file to the current directory. Cron jobs run from your $HOME directory, so if you want to wr... | Cron not working with shell script |
1,462,031,588,000 |
*/30 */30 * * * python /root/get_top.py
I'm trying to run a script every 30 hours and 30 minutes. Is the syntax above proper for that?
I've had multiple people tell me that */30 is not a valid value for the hour column, since it's greater than 24. If that's true, how do I make a cron for a job that should run every ... |
The simplest solution would probably be to run a cronjob more frequently and use a wrapper script to quit without doing anything if not enough time has passed.
To figure out how often you need to run, take the greatest common factor of cron's limits and your desired interval.
So, for "every 30 hours, 30 minutes", that... | Setting up a cron for every 30 hours in Debian |
1,462,031,588,000 |
How do I invoke a crontab command so that I can schedule to run a script with a 20 minute delay based on some condition?
Edit: What if I wanted a command that schedules a script to be executed only as many times as the condition evaluated to true in the system? What are my options?
|
Put the logic code for testing your condition in the script itself, don't try and put it in (or associate it with) cron - complex logic is not what cron was designed for.
So, in your script you test the condition and, if it evaluates to true, your processing code runs. If it evaluates to false, exit the script cleanl... | Conditional crontab command in bash script |
1,462,031,588,000 |
According to Artur Meinild's answer here, the "day of month" and "day of week" fields of a crontab are mutually exclusive. However, according to man 5 crontab (for cronie, if it matters):
Commands are executed by cron(8) when the 'minute', 'hour', and 'month of the year' fields match the current time, and at least o... |
The POSIX specification for crontab, being worded in the language of a standard—aiming to minimize ambiguity—has probably the clearest explanation (emphasis added, paragraph split for clarity):
The specification of days can be made by two fields (day of the month and day of the week).
If month, day of month, and da... | Are the "day of month" and "day of week" crontab fields mutually exclusive? |
1,462,031,588,000 |
There is a record:
45 * * * 1 script.sh
and
45 0-23 * * 1 script.sh
The desired effect is to run the script 45 minutes after every hour on Mondays.
Are they identical? If not, what is the difference?
|
Yes, they are identical.
I'd suggest the first syntax as it is more concise.
| Correctly defining a Cron schedule for process to be run every hour |
1,462,031,588,000 |
I have a file in server A which I am able to do transfer to server B using scp.
I need to do this through a cron entry. server B has a password.
How do I perform this?
|
Don't use password authentication. Use ssh keypairs.
Karthik@A $: ssh-keygen #keep the passphrase empty
Karthik@A $: ssh-copy-id B #enter your B password
#^ this will copy your public key to Karthik@B:.ssh/authorized_keys
From then on, you should be able to ssh from A to B (and by extension, scp from A to B) with... | How do I scp a file from server A to server B from cron? |
1,462,031,588,000 |
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 machine freely without typing it again while the ssh-agent is running.
The reason I was drawn to the article in the first p... |
Restrict the commands that can be invoked by the key
If an SSH key is going to be used by any kind of automated or unattended task, you should restrict what commands it is able to execute on a remote machine, no matter what decision you make about how and where to store the key.
Use something like this in ~/.ssh/autho... | Should the key for an automatically running cron job that runs over ssh not have a passphrase? |
1,462,031,588,000 |
I need two very specific cron statements:
A cron entry that would run on the 2nd Monday of each month every 4 hours beginning at 02:00 and execute the file /opt/bin/cleanup.sh
A cron entry that would run at 18:15 on the 3rd day of every month ending in an "r" that executes /opt/bin/verrrrrrrry.sh
I've already trie... |
To have something execute only on the second Monday of a month the day of week value needs to be 1 and the day of month value has to be 8-14, the hour has to be 2,6,10,14,18,22 and the minute 0. However as dhag correctly commented and provided a solution for, when you specify both the day of week and the day of month ... | How do I format these two complex cron statements? |
1,462,031,588,000 |
I have a backup.sh file that launch an rsync command. This rsync is to backup my dedicated server on a RaspberryPi running raspbian.
(I use keychain so I don't need to type any password etc ...)
The problem is that when I launch the batch manually everything works, but when it's crontab (with the same user) I have the... |
(I use keychain so I don't need to type any password etc ...)
Ok, so you need to tell the program running in your cron job how to find your keychain.
SSH looks for an SSH agent (which keychain emulates) via the environment variable SSH_AUTH_SOCK. So you need to set this environment variable in your crontab.
In a typ... | Rsync problem with cron and no problem manually |
1,462,031,588,000 |
My first solution to this was to execute date +%Y%m%d%H%M and put that format of numbers into a file, and run the script every minute from cron. Then if the date from the file matches the date command, the script would do something. Then it would update that file for the next day plus 3 minutes. Is there a better way ... |
You can use the at command from within your script (or a wrapper). Give it the time to run the next iteration.
echo '/dir/scriptname' | at 'now + 1443 minutes'
Put that line as near as possible to the beginning of the script to reduce drift.
| In linux, would it be possible to run a script every day 3 minutes later than the previous day? |
1,462,031,588,000 |
I'm using vixie cron on Debian/Ubuntu. How to set a custom directory to be read by cron? I want to lead crontab to run commands found in a series of files, e.g.
/home/cron/*.cron
or perfectly
/home/*/cron/*.*
In fact, instead of putting cron commands in /var/spool/cron/crontab/root, I want to spread commands in thes... |
Cron in debian reads commands from 3 locations - first is users crontabs in /var/spool/cron/crontabs/$user, then it reads global /etc/crontab and then all files from /etc/cron.d.
But you can't easily have multiple crontabs per user. Only files in /var/spool/cron/crontabs are per-user. The other two are system-wide and... | Custom directory for cron commands |
1,462,031,588,000 |
Currently I need to have a program running all the time, but when the server is rebooted I need to manually run the program. And sometimes I'm not available when that happens.
I can't use a normal configuration to restart my program when the server is starting because I don't have root access and the administrator do... |
I posted this on a similar question
If you have a cron daemon, one of the predefined cron time hooks is @reboot, which naturally runs when the system starts. Run crontab -e to edit your crontab file, and add a line:
@reboot /your/command/here
I'm told this isn't defined for all cron daemons, so you'll have to check ... | how to ensure a program is always running but without root access? |
1,462,031,588,000 |
I have a crontab script which read an environment variable with sensitive information(like a decryption key). The crontab entry is defined like that:
30 3 * * 5 VAR="pw" /usr/bin/script.sh
Is it safe to store something so sensitive in this way? If not, how can i improve it?
Thanks for the help.
|
Putting the variable in the crontab file and in the environment is secure in the sense that other users can't access it. However, it runs the risk of accidental disclosure, for example if you post the crontab line when asking for debugging help, or if you copy it and send it to someone as an example of how to automate... | Is it safe to call an environment variable from a crontab script? |
1,462,031,588,000 |
I work in a team. We have a CentOS Linux machine. There's a user there called www. We run cron jobs as that user, i.e. I can type sudo -u www crontab -e to see/edit the crontab, and my teammates do the same. However, I like to use nano as my editor, but the crontab opens in vim, because that's the EDITOR for the www u... |
You can specify the EDITOR variable as an argument to sudo:
sudo -u www EDITOR=nano crontab -e
| How to open the crontab of another user in my editor of choice? |
1,462,031,588,000 |
I've searched through some answers but nothing seems to clarify my confusion.
I have a cron job I want to run every 5 minutes:
*/5 * * * * cd /mnt/internal-storage/coindata && shell/command coins update
Do I place this in the /etc/cron.daily folder or create a /etc/cron.minutely?
Also what kind of file I create ins... |
The best solution for this is likely to add a line to your crontab. Accessing the crontab file may differ between implementations of cron, so I've provided commands for the two cron implementations in the official Arch repos. If you want a solution that does not require a specific cron implementation, I've written ano... | Running a cron job every 5 minute on arch |
1,462,031,588,000 |
I want to set up a job to run every 15 minutes, starting at the 5th minute.
This is my crontab line:
5/15 * * * * /root/job.sh >> /root/job.log
But it only runs once an hour, on the fifth minute. I confirmed by checking /var/log/syslog.
On Debian 7.8.
|
Have you looked at this?
I think what you are looking for is:
5-59/15 * * * * /root/job.sh >> /root/job.log
| Why is cron ignoring a / (forward slash) interval? |
1,462,031,588,000 |
I have a bash script that emails me whenever a web server is not responding, and the script is ran by cron every 5 minutes. However, if the website goes down for a few hours, I'd receive too many messages instead of just one.
What's the best way to make it email only once? Should I use an environment variable and che... |
I don't think you can use environment variables, as they won't persist between script "runs".
Alternatively, you could write to a temporary file in /tmp or somewhere in your home directory, then check it each time?
For example, something like
#!/bin/sh
output=$(wget http://lon2315:8081 2>&1)
pattern="connected"
tempf... | Run crontab only if condition |
1,462,031,588,000 |
I have a cron job that runs every minute on an Ubuntu 12.04 box
$sudo crontab -e
* * * * * mylogin /pathto/file.sh > /log/filelog
If I run file.sh, the bash script does some stuff and echos out runs:
$ ./file.sh
runs
If I check the log of cron tab it shows that the job is running:
Jul 10 12:41:01 localhost CRON[181... |
Specifying a username like mylogin is for the /etc/crontab file. With your command sudo crontab -e you are actually editing /var/spool/cron/crontabs/root and you should not specify a username in such a file, only in /etc/crontab.
If you have to run the command as user mylogin you have to put the line in /etc/crontab ... | Why isn't this crontab job running |
1,390,561,389,000 |
Could someone explain what the apt script is doing in cron.daily please? I can't find any documentation on it.
NOTE: I'm trying to investigate a server-server communications issue which frequently occurs around midnight - and I want to rule out the cron dailies.
|
Depending on the configuration, it essentially does the following:
apt-get update (update the package lists)
apt-get -y -d dist-upgrade (download all upgradeable packages)
unattended-upgrade (auto upgrade all upgradeable packages, requires the package unattended-upgrades to be installed)
apt-get -y autoclean (autocle... | What does /etc/cron.daily/apt do? |
1,390,561,389,000 |
A line in my cron.daily script not work as expected. I haven't any special smtp mail server in system,
this line
rsync -avun --inplace /oneuser/file.xls /otheruser/file.xls| mail -s "$0 $?"
provide Cannot open mail:25 message
What Do i need to setup a local mail subsystem? I preffer simple mailboxes to email ser... |
I recommend you just install postfix for the local mail delivery. On Ubuntu at least it will interactively ask about your setup, which includes a local delivery only option.
In addition you can make a local account mailboy for mail delivery and allow all people to read the mail delivered to that account.
In order to g... | set up local mail delivery to user from cron script |
1,390,561,389,000 |
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? grep / top / ulimit?
Can one notify the user via the
command line if something like this
happens?
What alternatives are... |
Instead of writing a script yourself you could use the verynice utility. Its main focus is on dynamic process renicing but it also has the option to kill runaway processes and is easily configured.
| cronjob to watch for runaway processes and kill them |
1,390,561,389,000 |
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 crontab, the output of mycmd is empty. When i call /usr/local/bin/mycmd inside of myscript.sh everything works fine again.
S... |
You have it exactly right - the environment of cron may have a PATH that does not include /usr/local/bin/. You can fix this by, in your script, appending that directory to the PATH:
PATH="$PATH:/usr/local/bin/"
The best practice, though, is indeed to use explicit paths for all external binaries that a script calls j... | Absolute path in bash scripts |
1,390,561,389,000 |
I want to run this program as root. It activates a virtual environment and runs a python program in that virtual environment.
The program looks like this
$cat myfile.sh
source /pathto/venv/bin/activate
python /pathto/rsseater.py
If I just run it as root I get
$ sudo ./myfile.sh
./myfile.sh: 2: ./myfile.sh: source: ... |
You generally want to add a call to an interpreter at the top of your scripts, like so:
$cat myfile.sh
#!/bin/bash
source /pathto/venv/bin/activate
python /pathto/rsseater.py
This may seem very similar to what you have but is it in fact very different. In your scenario you're attempting to run the commands within th... | sudo source: command not found |
1,390,561,389,000 |
I have this bash script:
while [[ 1 ]] ; do sleep 3600 ; ./notify.sh --text "ricordati di bere" && play /mnt/musica/login.wav && zenity --info --text="<span size=\"xx-large\">Time is $(date +%Hh%M).</span>\n\nricordati di <b>bere</b>." --title="drink time" ; done
I'd like to execute this script (from 8:00 o'clock, ... |
You would do the scheduling with cron. The schedule would look like
0 8-19 * * * /path/to/script
or
0 8,9,10,11,12,13,14,15,16,17,18,19 * * * /path/to/script
and the script would look like
#!/bin/sh
./notify.sh --text "ricordati di bere" &&
play /mnt/musica/login.wav &&
zenity --info \
--text="<span size=\"xx-... | specify a time interval in which to execute a certain script |
1,390,561,389,000 |
I have a cron script that runs a few times every day throughout the year. However, around Christmas it should work differently. So my script looks basically like this:
# m h dom mon dow command
26 16 * JAN-NOV MON-THU (echo 14 `date`) >> /var/log/cron.www-data 2>&1
26 16 1-18 DEC MON-THU (echo 6 `date`) >> /var/log... |
The reason can be found in crontab(5):
Commands are executed by cron(8) when the minute, hour, and month of year fields match the current time, and when at least one of the two day fields (day of month, or day of week) match the current time.
(Emphasis added)
I believe you want your script to run at the specified ti... | Why does this cron job run? |
1,390,561,389,000 |
When attempting to establish an ssh tunnel, I noticed that even if the connection fails, the process stays alive. For example, if I try to run this command while hostname is down:
/usr/bin/ssh -f -i /home/user/.ssh/id_rsa -N -R 3000:localhost:22 user@hostname
Occasionally I get the response:
Warning: remote port forw... |
For anyone else who may find the answer, I found the option that I wanted in this answer: adding -o ExitOnForwardFailure=True to the command forces ssh to exit if the port forwarding failed, instead of creating a zombie process:
/usr/bin/ssh -f -i /home/user/.ssh/id_rsa -N -R 3000:localhost:22 user@hostname -o ExitOnF... | SSH process staying alive even if connection fails? |
1,390,561,389,000 |
When I want to manipulate Unix cron, I do
crontab -e
then type (or paste) my directives.
How do I paste directive to crontab directly from a script?
In other words: Instead of pasting content inside crontab -e, I want to paste and save it there from outside, ready from a script, so to automate things up.
I ask this ... |
Per Ipor Sircer's answer about the usage of cron, i.e.
man crontab:
crontab [ -u user ] file
The first form of this command is used to install a new crontab from
some named file or standard input if the pseudo-filename ``-'' is
given.
this means that you send the lines you want in your crontab... | Is it possible to write to the crontab from a multipurpose script? |
1,390,561,389,000 |
To my surprise a trial of using crontab and rsync for backups of some test files, that I started last December (2015), is still running although, in the only crontab file I have, the only line is
#55 20 * * * /home/Harry/testrsync/trial_bak.sh
which is, or should be, commented out by the # added when I thought I had... |
The cron daemon takes crontabs from several files.
Dir /etc/cron.d and file /etc/crontab are special, they can be manually edited and the daemon will always see the new version automatically. Also these are the only crontab files which have also username field.
The crontabs of individual users (usually in /var/spool/c... | Why is this commented out crontab file line executed? |
1,390,561,389,000 |
I am using Linux Mint 17.
I want to be informed every 50 min, at every hour for small break.
Here is cron job:
nazar@desktop ~ $ crontab -l
DISPLAY=:0.0
XAUTHORITY=/home/matrix/.Xauthority
00 13 * * * /home/nazar/Documents/scripts/lunch_break_job.sh # JOB_ID_2
50 * * * * /home/nazar/Documents/scripts/pc_break.sh # J... |
You need to set XDG_RUNTIME_DIR as well. Change your crontab to this:
DISPLAY=":0.0"
XAUTHORITY="/home/nazar/.Xauthority"
XDG_RUNTIME_DIR="/run/user/1001"
00 13 * * * /home/nazar/Documents/scripts/lunch_break_job.sh # JOB_ID_2
50 * * * * /home/nazar/Documents/scripts/pc_break.sh # JOB_ID_1
* * * * * /home/nazar/Docume... | Notify-send doesn't work at Cinnamon |
1,390,561,389,000 |
System: Xubuntu 13.10
When I have this crontab entry
*/5 * * * * cat /home/dbk/.bash_aliases &> /home/dbk/Desktop/junk
junk has a byte size of 0.
Running
$ cat /home/dbk/.bash_aliases &> /home/dbk/Desktop/junk
gives a file with a proper size and content.
|
The probem because cron run task with sh. &> is a shortcut to redirect both stderr and stdout to the same file in bash, not in sh.
In sh, your command:
cat /home/dbk/.bash_aliases &> /home/dbk/Desktop/junk
meaning run two commands separately:
Run cat /home/dbk/.bash_aliases in background
cat /home/dbk/.bash_aliases ... | Why does redirection in crontab result in a zero byte file? |
1,390,561,389,000 |
I want to schedule a file to run using the at command, as described in this tutorial. I see that the at command supports the posix format -- but I don't see any mention of timestamps. Surely it is possible to schedule a job at a given timestamp.
$ man at | grep timestamp
|
From usr/share/doc/at/timespec, it doesn't look like it. But you can always use date to convert your timestamp, eg:
at "$(date --date=@1393419435 +'%H:%M %D')"
date takes a timestamp in seconds, so don't forget to trim fractions of seconds if needed.
| Is it possible to use the at command to schedule a job to run at a given timestamp? |
1,390,561,389,000 |
If a cron job produces output it is e-mailed to the user's account.
I would like to redirect this e-mail to another e-mail account. Preferably on a user-by-user basis.
I've looked into some options that are often mentioned in other postings:
Using the cron MAILTO variable. Won't work. That one is not
supported on Sol... |
If you want to forward all of a user's mail, not just the mail from Cron, Solaris does support ~/.forward. Solaris also supports global aliases in /etc/mail/aliases; if you modify this file, you need to run newaliases.
If you only want to forward mail from cron, you can set a filter in ~/.forward or /etc/mail/aliases.... | Solaris: how to forward cron e-mails? |
1,390,561,389,000 |
I have an init.d script to start crond which specifies the following for start():
start-stop-daemon -S --quiet --make-pidfile --pidfile /var/run/crond.pid --background --exec /usr/sbin/crond
However, the PID is always one number higher than what's recorded in /var/run/crond.pid. Does anyone have any idea what's goi... |
The crond program is designed to be daemon. When it starts, one of the first things it does it fork a child and exit the parent. This is designed for environments where the caller is waiting for the program to exit before proceeding, whereas the daemon needs to continue executing in the background.
caller ---- fork-->... | start-stop-daemon makes cron pidfile with wrong pid |
1,390,561,389,000 |
I'm writing a bash-script that will be run as a cron job everyday. Very basic, I was wanting to change the wallpaper daily. I have mint-14 with mate.
The thing I'm getting caught up on right now is, I want to have the user's home path detected automatically. If I don't do this I would have to change it for all ot... |
$HOME is not set in cron, so put this in a script, and let your cron job execute that instead,
(Remember to set the execution bit for that script with chmod +x XX)
#!/bin/bash
mateconftool-2 -t string -s /desktop/mate/background/picture_filename ~/Pictures/daily
Or in your cronjob,
HOME="$(getent passwd $USER | awk ... | Users home path in a bash script |
1,390,561,389,000 |
EDIT: THE SOLUTION
With Tim's help I determined that larger writes of data were failing versus smaller ones. Why they didn't fail when I ran the script interactively, I don't know...But here was the fix (new mount option of wsize=4096):
if mount -t cifs -o guest,wsize=4096 //drobonas/public /mnt/drobonas-public; then
... |
Have you verified that the backups are being created with all the correct contents?
There are several reasons you could be seeing the errors.
You maybe seeing purely informational errors related to file attribute setting at creation time (during the tar and mv commands). the NTFS or FAT filesystem underlying the CIF... | cifs write errors in cron job |
1,390,561,389,000 |
I have a machine (A) behind a firewall with no access to the Internet, on this machine I can NFS mount directories on another machine (B) which can access internet, and is accessible from Internet, but I cannot install anything on this machine (B).
I want to keep a directory on (A) in sync with my Dropbox (that I us... |
You may be able to use Unison to synchronize your files. Unison uses the rsync protocol and can run over ssh. You may need to copy the executable into your directory on the remote system.
Using rsync may cause problems as it is difficult to synchronize file deletions.
EDIT: To sync a folder on A from system C (wi... | Using rsync + cron to sync a machine behind a firewall with my dropbox |
1,390,561,389,000 |
I want to use cron and this script (http://askubuntu.com/questions/23593/use-webcam-to-sense-lighting-condition-and-adjust-screen-brightness):
import opencv
import opencv.highgui
import time
import commands
def get_image():
image = opencv.highgui.cvQueryFrame(camera)
return opencv.adaptors.Ipl2PIL(image)
ca... |
In older kernels there was brightness control file somewhere in /proc, but I think that it was the same functionality as /sys in your code snippet. In this /procfile there was several levels of brightness that you could use and probably the same is in that mechanism. Try to cat /sys/devices/virtual/backlight/acpi_vide... | How to use cron + python to regularly adjust screen brightness? |
1,390,561,389,000 |
I posted this in Raspberry Pi, but was told that it was better suited in a general linux or programming area. So I figured I'd ask here now...
I am putting together a kiosk that should play video. I'm using a NUC with Raspberry Pi Desktop. Everything works but automating the audio with Cron. I work in a school and bla... |
After all the help I received I was ultimately able to find a solution. It's not the solution I really wanted and it's not very clean, but it works so I'm posting it here.
The Issue as I Understand it
The heart of the problem seems to be that running Amixer as a generic user elevates to a Sudo permission no matter wha... | Cannot Schedule Audio Volume Change with Cron (tried direct in cron, python, etc...) |
1,390,561,389,000 |
I am trying to organize my webcam picture files into folders otherwise I get thousands of pictures in one folder.
I have a script foscam-move.sh (from Create sub-directories and organize files by date) with the following:
#!/bin/bash
for x in *.jpg; do
d=$(date -r "$x" +%Y-%m-%d)
mkdir -p "$d"
mv -- "$x" "$d/"
... |
cron doesn't run with the same environment as your user. It's likely having issues because it's not in the proper directory. Have your script cd to the directory containing the images before executing your for loop.
| Sort files in a folder into dated folders |
1,390,561,389,000 |
My at on Mac OS X 10.11 seems to be incapable of launching jobs. I tried:
echo "date > foo" | at now
Running atq afterwards shows the job queued and no file foo was created. To make sure the problem isn't a date mixup, I ran:
$ date && echo "date > foo" | at now && atq
And both date and atq showed the same time.
I... |
Seems that the at command doesn't work out of the box.
In my test, for example:
OS X, according to this SU answer needs:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist
raspbian needed:
sudo apt-get install at (which will install and run atd, at daemon)
Arch Linux had at installed, ... | How can I get at to work on OSX? |
1,390,561,389,000 |
I have a temp directory set up where users can place whatever files they need to send to other users via HTTP. The owner of this directory is an SFTP user, and cannot run cron jobs.
I have one shell user that can run cron jobs, but does not have permission to edit files in the SFTP user's directory.
I have an admin u... |
Edit the /etc/sudoers file (use visudo!) and add an entry that allows the shell user to have sufficient privileges to run a specific command, without having to enter a password. If you use a script, make sure the script cannot by edited by anyone but root.
In /etc/sudoers, where shelluser is the shell user name:
shell... | Emptying a directory owned by another user weekly |
1,390,561,389,000 |
I have a server monitoring script which, among other things, checks the state of an IPSec tunnel using
ipsec auto --status
It works like a charm when run from the console (as root) but as soon as I run it from a (root) cronjob, the command fails: no output at all.
I even tried to create this simple root cronjob:
*/1 ... |
It sounds like cron is not seeing ipsec in the path. It's a pretty good habit to include absolute paths to binaries in crontab. There is probably some complaining in /var/log/messages or /var/log/cron.
*/1 * * * * /usr/sbin/ipsec auto --status
You could also add the PATH environment variable to the top of the crontab.... | ipsec auto --status fails in cronjob |
1,390,561,389,000 |
I do a lot of work on in the cloud running statistical models that take up a lot of memory, usually with Ubuntu 18.04. One big headache for me is when I set up a model to run for several hours or overnight, and I check on it later to find that the processes was killed. After doing some research, it seems like this i... |
You can ask the kernel to panic on oom:
sysctl vm.panic_on_oom=1
or for future reboots
echo "vm.panic_on_oom=1" >> /etc/sysctl.conf
You can adjust a process's likeliness to be killed, but presumably you have already removed most processes, so this may not be of use.
See man 5 proc for /proc/[pid]/oom_score_adj.
Of c... | Trigger a script when OOM Killer kills a process |
1,390,561,389,000 |
I am running CentOS 7 with XFCE as my DE. I made a bash script, originally stored in ~/bin (I have since deleted it), which I wanted to have run automatically at startup. I somehow succeeded, but I have tried to remove it from my autostart programs, to no avail.
when I run ctrontab -e, I am given an empty file to ed... |
If you are running systemd you can create a service that will start yourt software and then use systemctl enable [your-service] to start it on boot up. If your using openrc(old init) then you can use a similar method just use rc-update add [service] default
| Other than crontab, what other ways can one add programs to run at boot time? |
1,390,561,389,000 |
I have a cronjob that runs php5 wp-cron.php every minute to update my website.
However something happened and i had 30+ instance of it (31 is marked on this one dump of ps aux). It ate up my ram, caused additional instance to terminate do to lack of memory and caused me not to be able to ssh into the box.
I can't unde... |
For the goal to prevent multiple copies from running, use flock (Linux), lockf (FreeBSD), shlock (provided with some systems, less reliable). This won't limit execution time but ensures only one process is running. Then, if it hangs, you can analyze its state on the fly.
You can limit CPU time of the spawned process u... | crontab, instance, memory issues+spamming |
1,390,561,389,000 |
How can i dump files from my CentOS box to Dropbox account? As regular nightly backup task.
|
0 1 * * * cp -a /tmp/files ~username/Dropbox/tmp_backups_$(date +%Y%m%d)
Breakdown: Every day at one am make an archive copy of /tmp/files into a folder with the date as part of the name in 'username's dropbox.
| How can i dump /tmp/files in CentOS to Dropbox using crontab? |
1,390,561,389,000 |
We are creating a new cron job under /etc/cron.d.
This cron job has around 56 lines, and all commands should be executed at the start of each month.
I am looking for suggestions to validate the syntax of the cron job.
I mean, how can I verify if the cron job file is configured correctly without mistakes - is there so... |
Here's a start to a validator, written in awk, that checks:
for non-commented lines
for lines with enough fields to look like a crontab entry
where the day-of-month value in $3 is not 1 or *
where the month value is not *
... then print the (offending) line.
On a sample input of:
53 23 * * * root /usr/lib64/sa/sa2 -... | How to validate the syntax in cron job [closed] |
1,390,561,389,000 |
I've just set-up one cron-job in cpanel, but although it seems to be executing the script it doesn't work as intended.
Here is the cron job command in cpanel:
/bin/sh /home/my-username/cronjobs/sedclearmalw.sh
and here is the content of the script :
#!/bin/bash
cd ../public_html/
grep -rl '_0xaae8' . | xargs sed -i '... |
The problems is due to the use of a relative path. When cron runs a scheduled job, it uses the home directory of the owner as its working directory, e.g., if I schedule a job as the root user, its working directory will be /root/ (on a Cent OS system).
You should specify the absolute path in your cd command. If you’re... | shell script for cron job |
1,390,561,389,000 |
I'm looking for a method to start an application immediately after boot-up. This application times out after 1 hour. I'd like to then start another instance of this application 1 hour after the initial boot-up (following the timeout of the initial application). I had been thinking that Cron might be configured (clever... |
Given your description, I would start the application with a systemd (since that is what I have on all my machines) .service file.
In that service file, I would point to a script that wraps your application in a simple while loop. Something like this:
#!/bin/sh
while true; do
/path/to/your/application
done
This ... | Initiating an application after OS bootup, then restarting that application every hour thereafter |
1,390,561,389,000 |
I'd like to run a script (let's say myScript.sh) every time a yum update or yum install command is executed.
So if I run yum update someprogram then myScript.sh should be executed right after that. Is this possible?
Currently I could run a script if I put it in the ".spec" file when I build the rpm to install, but we ... |
You can create bash function in .bashrc :
myyumfunction() {
yum update $1
myScript.sh
}
Bash functions that you define in your .bashrc are available within your shell. You can call your function like this:
$ myyumfunction someprogram
| How do I run a script every time "yum update" is run? |
1,390,561,389,000 |
I want my computer to play some given .mp3 every 2 hours. I want it to run at startup, and be modifiable with a given .conf file. The choice of .mp3 will also be in the .conf file.
The reason is, I need this to remind me to eat regularly.
Now, I'm familiar with C, but I don't know anything about daemonising C prog... |
Just source the conf file in your bash script and use mpg123 to play the mp3. For example in ~/.music-cron:
TARGET_MP3="$HOME/file.mp3"
And in the bash script:
. "$HOME/.music-cron"
mpg123 $TARGET_MP3
Then use cron to schedule the script every two hours and after the system boots up:
0 */2 * * * /path/to/script.sh
@... | What's the easiest way to set up a 2-hour alarm? |
1,390,561,389,000 |
I have a simple periodic cron task that must run as root. I want to use Zenity (or similar) to display a GUI informational dialog to user 1000 (or logged in user or all users) when the cron task finishes.
I'm looking for a simple, easy, quick solution. I'll adapt to the requirements of such a simple solution.
Here's ... |
Based on Mel Boyce's answer, here's what worked for me. This is KDE-based. But I also tested it with Zenity and the same approach works. It is basically the same thing Mel Boyce recommended, but with a few tweaks to get it to work for me. I don't delete the updateNotification.txt file, for example. And I don't use pri... | How to display a (zenity/GUI) dialog to the user after a root cron task has completed |
1,356,718,345,000 |
There exists a Git repo that is on one server, we want to generate doxygen output for it on a different server. The following command works for me but has the downside of sending a mail everytime the repo is updated because Git uses stderr for progress reporting (a quick search via the almighty oracle suggests they co... |
Relying on the mailing capabilities of crond too much may yield various problems. Depending on your your crond they are perhaps just not flexible enough.
For example, often, as you described, one cannot configure that only an exit status != 0 should trigger the mailing of stdout/stderr. Another issue is that, for exam... | Mail cron output only when Git throws a real error |
1,356,718,345,000 |
I am trying to synchronize:
/var/www/CI_MAIN/
according to the changes made in:
/home/coco/workspace/CI_MAIN/
(PDT's workspace).
To do this, I entered
sudo crontab -e in the command line,
and I added the following line to the end of the opened file :
@reboot lsyncd -direct /home/cockroach/workspace/CI_TEST/ ... |
When writing cron jobs you should use the absolute path to the binary, if you haven't already done a export of your PATH in crontab.
Find out where lsyncd is located with:
$ command -v lsyncd
Example output: /bin/lsyncd. Copy the output and replace lsyncd with the absolute path.
| How to one way sync two folders on startup |
1,356,718,345,000 |
I have created a script called connection.sh, it is used to automatically connect to my vpn :
#!/bin/bash
nmcli connection up MyVPN
I have already tested it, and it works if I launch it manually, but if I use crontab to launch it to a specific time it seems it doesn't work.
I stored the script in /home/MyUser/Scripts... |
It's because your shell uses environment variables that have different values then the environment variables that cron job have. Not all of the environment variables have different values but some of them. In not familiar enough with nmcli but you have to find out what environment variables it uses and then set them o... | Crontab and NMCLI |
1,356,718,345,000 |
I'm trying to figure out a good solution to the following problem:
crontab contains some default rules (A,B,C)
I have a setup.sh script that should append rules from a file my.cron to crontab (suppose rules X,Y,Z). The resulting rules should be A,B,C,X,Y,Z
I cannot use crontab my.cron as it overwrites the existing ru... |
From what I can tell, there's no way to tell crontab to refer to a set of files to collate the rules (without duplication or overwriting)/
There is, but not for user crontabs. Use individual files in /etc/cron.d for each cronjob. Then you can safely add, remove or update specific cronjobs without worrying about othe... | Update crontab rules without overwriting or duplicating |
1,356,718,345,000 |
I don't know where I can find more information about crontab, so I ask here.
Crontab is it multithread? How does it work?
|
Probably not. All cron has to do is (to express it simplified) watch until it is time to run one job or the other, and if so, fork a process which runs that job and periodically check if the job is finished in order to clean it up.
MT could be used for this waiting, but I think that would be overkill. With the wait()/... | Is crontab multithread? [closed] |
1,356,718,345,000 |
I'd like to execute a task at a given time, once.
I know I can just use crontab -e to add it there, but I'd like to do that through a shellscript. crontab -e gives me some temporary file to edit which is unpredictable.
Also, once the task executes I'd like to remove it from the crontab again to make sure it'd not leav... |
I think the at command is what you are after.
E.g.:
echo "mail -s Test mstumm < /etc/group" | at 16:30
This will e-mail you a copy of /etc/group at 4:30 PM.
You can read more about at here: http://www.softpanorama.org/Utilities/at.shtml
| Add a one-off scheduled task through a shell script? |
1,356,718,345,000 |
I have a bash script which is run every 10m by cron. The script performs an expensive calculation for some value (say variable x=value). I need to "cache" this value for 2-3 hours. What are possible solutions to this problem?
I tried memcached but it doesn't seem to play well with bash.
|
Write a second script that does the actual calculation and saves the result to a file:
# calculate $curval
printf '%s' "$curval" > /var/foo/value.txt
Schedule it with cron to run every 2-3 hours.
In the "every 10 minutes" script, simply read the current value from the file:
curval=$(< /var/foo/value.txt)
A nice refi... | How can I "cache" a variable in Bash? |
1,356,718,345,000 |
I accidentally typed this command without any arguments and hit enter, and it seems the terminal is running something, so my question is what crontab do when I give no arguments?
[root@localhost ~]# crontab
|
crontab with no arguments reads a new crontab from standard input, validates it, and then replaces the current user’s crontab with it.
To get out of your situation, without losing your existing crontab (if any), either kill crontab with CtrlC, or enter an invalid cron job definition (foo) and press CtrlD:
foo
# Now pr... | What does crontab do when I give no argument? |
1,356,718,345,000 |
I am using RHEL 5.4
I killed the cron daemon accidentally. I wanted to stop a cron task, didn't know how to do it, ended up killing the cron daemon itself. How do I start it again?
|
Depending on how your exact distribution is set up, /etc/init.d/cron start or variations thereupon might do the trick.
| How to start the cron daemon |
1,356,718,345,000 |
I am running an old version of Ubuntu (14.04 LTS) because my video card is no longer supported by the kernel in newer releases of Ubuntu.
I discovered in my cron.daily directory a script called popularity-contest which is "phoning home" every day. Can I remove it safely?
This link says it was reporting to the develop... |
Yes, you can disable this feature safely:
sudo apt-get purge popularity-contest
This will delete the cron script and everything else related to the package, apart from its log files.
(Note that your system might not be configured to phone home — the package needs to be installed, and it needs to be set up to phone ho... | Popularity Contest in Ubuntu |
1,356,718,345,000 |
Using the at command I can run a script once in the future:
at now + 1 minutes -f ~/script.sh
or run a string command now then return the result in the future:
echo "xyz" >> ~/testtest.txt | at now + 1 minute
How can I instead pass a string command (as per example 2) that runs in the future and not now (as per examp... |
You could single quote the command and pass it to at as is:
echo 'echo "xyz" >> ~/testtest.txt' | at now + 1 minutes
Alternatively, if you're using bash or another script that supports process substitution, you can do:
at now + 1 minutes < <(echo 'echo "xyz" >> ~/testtest.txt')
This basically passes a filename to at... | Pass the "at" command a string command instead of a path to a script whilst having it run immediately |
1,356,718,345,000 |
I'd like to run a pretty simple script (is there a dir with name x in dir y if so move it to dir z–and x will only be there about once a day) every 15 seconds or so (one minute divided into 4*15 seconds). Does running cron jobs like that (where the scripts they run are not resource intensive) have a non-neglible negat... |
To answer the question in the title, no, most system do not experience much of a burden from running cron jobs. Much of the automated tasks that occur on a modern Unix system are kicked off by cron jobs.
Things such as rotating logs, and regenerating index files used by man are all kicked off via cron jobs.
If you're... | Does cron jobs per se represent a significant burden on a modern system? |
1,356,718,345,000 |
Server is Debian 6.0. In /etc/aliases I have;
root: [email protected]
This is so that root emails get sent directly to me. Today, a monthly script I have placed into /etc/cron.monthly has emailed me it's output. It a fairly simply script which looks like this;
#!/bin/bash
cd /a/directory
rm -rf ./*
wget http://www.si... |
An easier method is to instead of adding the script to the cron.monthly directory, you add it to an old-fashioned crontab, where you can specify on the crontab line that you want output to go to /dev/null. Like this:
crontab -e
to edit the crontab. Then add the following line:
@monthly /path/to/script > /dev/null
Th... | How to stop monthly cron output email |
1,356,718,345,000 |
In cron's manpage (cronie)
-p Allows Cron to accept any user set crontables.
I learned that cron daemon will implicitly search for and run the cron jobs defined in /etc/crontab, /etc/cron.d/* and /var/spool/cron/cronstabs/*.
What is -p used for?
Is it to explicitly tell cron to search for and run the cron jobs ... |
The CAVEATS section of the cronie's cron(8) man page says (emphasis mine):
All crontab files have to be regular files or symlinks to regular
files, they must not be executable or writable for anyone else but
the owner. This requirement can be overridden by using the -p option
on the crond command line.
So it... | What is `-p` used for `cron`? |
1,356,718,345,000 |
I'm going to make a bash script that is executed at boot and runs periodically.
I want it user-configurable, so that a user can add a cron job 0 * * * * my_script by running my_script add 0 * * * *, list jobs by my_script list, and remove by my_script remove job_number where the job number is listed in the output of m... |
Using cron is the correct way to schedule periodic running of tasks on most Unix systems. Using a personal crontab is the most convenient way for a user to schedule their own tasks. System tasks may be scheduled by root (not using the script below!) in the system crontab, which usually has an ever so slightly differe... | How do I add/remove cron jobs by script? |
1,356,718,345,000 |
I need to create a cron job that runs a bash script in background which does not end unless killed.
The bash starts a process that should keep running for about 28 hours then I need another cron job to kill it.
First cron runs every day at 0:00AM, starts the process.
Second cron runs at 4:00AM and has to kill the pr... |
Use timeout command, it is much easier:
0 0 * * * timeout 28h /home/script.sh
PS. Remember to use the full path in the crontab.
| CRON job that kills a process started by previous CRON |
1,356,718,345,000 |
My system is centos 6.5,
I write a simple bash shell to check if mysql is crashed, restart service again. I put it in /home/myspace/mysql.sh chown root:root /home/myspace/mysql.sh then run every minute by crontab.
#!/bin/bash
mysql --host="localhost" --user="root" --password="password" --database="test" --execute="sel... |
Force the PATH in your script, cron may not provides the same path as the one you have in a terminal session.
EDIT:
In a terminal get your PATH:
env | grep "^PATH="
PATH=/sbin:/usr/sbin:/usr/local/sbin:... (you will have different value
Cut and paste that line in your script just bellow the #!/bin/bash
#!/bin... | bash restart mysql when it gone run well in SSH part, but not in cronjob |
1,356,718,345,000 |
I have (from one tutorial) cron job which make weekly backup on my website and is working fine.
#!/bin/bash
NOW=$(date +"%Y-%m-%d-%H%M")
FILE="mysite.com.$NOW.tar"
BACKUP_DIR="/home/user/backups/"
WWW_DIR="/home/user/public_html/"
DB_USER="my_site_db_username"
DB_PASS="password"
DB_NAME="mysite_dn_name"
DB_FILE="mysi... |
Edit your crontab file and add:
MAILTO=your.email@your_provider.com
and at the end of the script add:
echo 'backup finished', $FILE
cron normally sends any output from the command it runs per email. Your script seems to be running silently, hence no email.
If you don't add the MAILTO, the mail will go to the user ru... | Cron jobs and mail notification |
1,356,718,345,000 |
I'm calling cpulimit from cron:
00 16 * * * /usr/bin/cpulimit --limit 20 /bin/sh /media/storage/sqlbackup/backups.sh
When the job kicks off, the CPU spikes and alerts as it always has, with no actual identifiable limit having taken place. The job itself iterates over a directory of many subdirectories and performs r... |
By default cpulimit doesn't limit child processes, so the rsync is not being limited at all. If you are running a recent enough version of cpulimit you should be able to use the --include-children (or -i) option. (See also this answer.)
$ cpulimit -h
Usage: cpulimit [OPTIONS...] TARGET
OPTIONS
-l, --limit=N... | cpulimit is not actually limiting CPU usage |
1,356,718,345,000 |
A common way to log crontab errors looks like below:
1 */8 * * * sh /pseudo_path/test.sh 2>> my_err_log
It's a concise command, but it can't record the error occurred time, and the path of script file is omitted.
So I wrote an error record function:
PROGNAME=$(readlink -f "$0")
SCRIPT_ERR_LOG_PATH="/pseudo_path/scri... |
Depending on the quantity of the logging information you're expecting to produce, it might be worth using the standard logger tool to write it to the user syslog in /var/log:
1 */8 * * * /path/to/myprog 2>&1 | logger -p user.debug -t 'myprog'
Here is an example of the output written to /var/log/debug on my Debian-bas... | Log crontab shell script errors with error occurred time? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.