Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I need to install some cron jobs with my Ubuntu installation package. The ones that run every day or hour are easy: I can just create a symlink from /etc/cron.daily to my script.
However, I also have a script that I would like to run every 10 minutes. There is no such thing as /etc/cron.minutely. Also I am not sure how to edit crontab without using the interactive editor (crontab -e). What is the best way to go about this?
Your package can simply put a file in /etc/cron.d/
The text file should contain something like this, to run a command every 10 minutes:
*/10 * * * * root /path/to/command
Google 'cron format' for more info, and yes, this belongs in askubuntu or superuser.
You need to add the username (root) to the line, as shown above. Apparently this is necessary for files in cron.d, but I can't find a definitive document.**
cron should pick this new job up automatically.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I am using ubuntu and I have written a python program to clean my download folder and a shell script to execute the program. But I need to run the script manually each time. Is there any way to run the script run automatically when a new file is added to that folder? I know there is inotifywait to monitor the folder but how to make that script runs from the time of reboot with setting corn??
I don't quite understand why you run Python script, from a bash script, and that Python script does clean your downloads folder. I think it would be much easier if you run just a bash script that cleans the downloads directly instead. This script would look like this:
#!/bin/bash
/usr/bin/rm -rf /home/<your_username>/Downloads
And save it as somescript.sh. Just remember to replace <your_username> with proper value.
As to how schedule running a script, one way to do this is using crontab utility in linux. It allows you to run programs at a certain time. Some examples you may find are here: crontab question, here crontab tutorial and here about crontab. Say, for example we would like to run above script at certain hour. Firstly run:
$ sudo crontab -e
To open crontab editor. Then you need to insert the line below to schedule running somescript at 6 pm everyday:
0 18 * * * /<path_to_the_script>/somescript.sh >/dev/null 2>&1
The entry in crontab has the following form:
minutes hour day month weekday (path to the script)
If you need help to start with specifying time, you might want to look at crontab generator. Also, just make sure that the script has the right privileges i.e. can be executed etc. After you save the crontab file it will be automatically scheduled. In case you want to schedule a task to run once, you might want to look into at commandline tool about at command.
Please note that you should more carefully prepare your question to make sure that everyone understands you. Ideally, provide some examples. This way you have a better chances to receive an answer that would actually help you, so I think it's a good deal. Welcome to the community :)
In order for a program to run always on a UNIX/Linux system, you might add it to the crontab, using the five asterisks, as mentioned in this serverfault post.
The best way to proceed here is to add a rm command in the crontab, using 2</dev/null at the end, in order for error messages (in case the file does not exist), not to flood your logs.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I have written a code which moves .trc files from source directive to backup directive. Now I have taken time (how much time older), source path and backup path as command line arguments for this file. Now when I invoke the script from sh, it works fine. But in crontab it is not working, which left me wondering if crontab allows passing command line arguments or not. My sh command is :
sh trace_bkp.sh 2 /home/adhikarisubir/test/basic_unix /home/adhikarisubir/test_bkp
where 2 defines 2 minutes older files, next one is soruce path and the last one is target path. I set the same in crontab as:
*/5 * * * * sh /home/adhikarisubir/test/basic_unix/trace_bkp.sh 2 /home/adhikarisubir/test/basic_unix /home/adhikarisubir/test_bkp
Yes, crotab lines can get arguments as the man page says so.
Most likely something goes wrong while calling that command that resides in the change of environment from your console to the not-a-console cron environment.
Usually its best to add logging functions to your cron line to get the output of whats happening.
*/5 * * * * sh /home/adhikarisubir/test/basic_unix/trace_bkp.sh 2 /home/adhikarisubir/test/basic_unix /home/adhikarisubir/test_bkp >> /home/adhikarisubir/test/basic_unix/cron.log 2>&1
Then read that log and you will see how it goes wrong.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have a Script that is supposed to be execute by the crontab. How can I verify this at this moment if the task was programmed to be executed several hours ago?
You should modify your crontab file by adding a MAILTO=<your email here> before your cron so that you will be emailed the results of the execution. This won't solve your problem of knowing if the script executed in the past, but it may help you avoid this issue in the future. To make sure you get an email, just add an echo "Running script!" line to the top of your script.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am using sphinx for searching. I get new data everyday which is added in the database.
I have to add this data into the sphinx search index so that it can be searched. For that I need to reindex the sphinx search index at regular intervals.
How can I set a cron in linux to do so?
a crontab is defined like this:
MIN HOUR DOM MON DOW CMD
so if you want to run a task on a daily basis try:
0 0 * * * /path/to/your/script
that will trigger the launch of your script everyday at 0:00
For more details, see the cron tag wiki
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
In a crontab file, should commands be specified with a trailing "&", or will the command run in the background anyway?
I have:
*/20 * * * * /home/me/monitor/check.sh /home/me/monitor/check.properties >> /home/me/monitor/check.log 2>&1 &
I've seen contradictory answers to this question in various places. Some say no need to put an "&", others that without the ampersand cron waits for output from the command, even though all output is redirected.
Every job that's run by cron is run in the background automatically, so no need for the &
See this too.