date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,593,723,601,000
I'm running unattended upgrade at random times on a computer. I have a cron to reboot at a set time daily. If my reboot cron runs in the middle of an update, will it wait to reboot or will it force a reboot in the middle of an install?
When you run reboot your init system kindly asks running processes to shut down by sending a SIGTERM signal. If they do not shut down within a reasonable amount of time (if you're on a machine using systemd this time defaults to 90 s) the init system will send a SIGKILL signal. We certainly don't want to kill a busy u...
Will reboot command wait for unattended upgrade to complete?
1,593,723,601,000
I'm on Kali Linux with VERSION_ID="2019.3" uname -a Linux kali 4.19.0-kali5-amd64 #1 SMP Debian 4.19.37-6kali1 (2019-07-22) x86_64 GNU/LINUX Trying to execute adjust_timezone.sh placed in /usr/local/startup_scripts/ #!/bin/sh echo "Adjusting timezone..."; ntpdate in.pool.ntp.org; The output of which ntpdate...
Your ntpdate is running before the network is up and functional. A better solution might be to use the systemd time synchronisation module rather than creating your own. Or install ntpd and let it manage your system's time.
Kali linux - Crontab @reboot is not executing
1,593,723,601,000
I have this directory structure at /var/sync: # tree -d /var/sync/ /var/sync/ ├── sync_bi │   ├── replicator => Replicator.php │ sync.php ├── sync_pfizer │   ├── replicator => Replicator.php │ sync.php │ replicator.sh │ sync.sh As you can see on each sync_* directory there is script called sync.php and on each r...
The simplest approach would be two find commands: find /var/sync/ -name 'sync.php' -execdir php {} \; find /var/sync/ -name 'Replicator.php' -execdir php {} \; That will look for files called either sync.php or Replicator.php, then cd into their parent directory and execute them with php. You could add the commands d...
Read each directory and perform actions in Bash script
1,593,723,601,000
I know the standard way to disable a task in cron is to comment the line with the task using the # sign in front of it, as with most Unix config files or shell scripts. e.g.: 53 23 * * * /home/dolan/y-u-du-dis.sh 2>&1 That's fine for just one task, but it's really annoying having to comment 100 lines or so... so ...
The answer from SF is accurate as far as it goes, though if all the lines you wish to comment are in one block there is a way "around" this problem. It's not standard practice, and the end result is individual comment markers on every line. My editor of choice for crontab files is vi, so other editors may or may not h...
Is there a way to comment more than one entry at a time in cron?
1,593,723,601,000
I have a situation where I may need to execute an SAP command line tool hdbsql when memory gets too low (to help clean out the HANA table cache). How I can best approach this? I did have an idea to extract the free memory value from the top command (or get free/max*100 to get a %, which is better) in a shell script ...
You could use awk to calculate the percentage and the test utillity to determine if the value exceeds 90%, for example. The cronjob could look like this: /usr/bin/test 90 -le $(/usr/bin/awk '$1=="MemTotal:"{t=$2} $1=="MemFree:"{f=$2} END{printf "%d", (t-f)/(t/100)}' /proc/meminfo) && command-to-cleanup The awk part e...
CRON Job To Execute Command On Low Memory
1,593,723,601,000
I have several file setup in my crontab, all those scripts must run every 5 minutes. The problem comes when those script need to much CPU and IO at a time and the machine become unavailable. To mitigate this effect, I'd like to know if there's an option to put 10 seconde between each script start. It should leverage...
Create one cron entry that is: */5 * * * * processA ; sleep 10 ; processB ; sleep 10 ; process C However, I recommend against this. I wouldn't use cron at all. Cron is not that smart. If you tell it to run a job every 5 minutes, and the job takes 6 minutes to run, you will get 2 processes running. By the end of th...
Cron several script every 5 minutes with 10 second between each script
1,593,723,601,000
I have a crontab that includes many users updating it. The problem is that because of this, it is not easy to know who did what modification of a cronjob. I was thinking to create a script to do a diff of the crontab with a previously saved version to at least be able to see what has been changed, but I thought that ...
Subversion I would put the contents of the crontab under subversion control and only grant access to this user through sudo. Specifically I would only allow people access to the a command via sudo that would take the head from subversion, and install it as the latest crontab for this particular user. This will provide...
How can I manage my crontab effectively to avoid issue by multiple updates by multiple users?
1,593,723,601,000
How do I make cron daemon check cron entries from more than one files. In my project I need to frequently update cron file, so instead of manipulating the existing file I was planning to write my project cron entries in a dedicated cron file.
Users have 3 options: Access their own crontab entry using the command crontab -e. If they have sudo privileges on the system they can add crontab files to the /etc/cron.d directory. Add scripts to one of these directories: /etc/cron.daily /etc/cron.hourly /etc/cron.monthly /etc/cron.weekly
cron from multiple files
1,593,723,601,000
I currently use an application called MxEasy on my linux servers to display video from a couple of IP cameras. The software is rather buggy and crashes occasionally. I've wrote a script that checks to see if the application is running and if its not... it launches the application. I've tried adding this line to my cr...
Rather than check every few minutes, write a loop that relaunches the program when it terminates abnormally. But don't roll your own, there are plenty of existing programs to do that. See Ensure a process is always running
Watchdog script to keep an application running
1,593,723,601,000
need some help to identify top of the hour in a shell script? I have a cron which runs and execute a shell script in every 10 minutes but I don't want this script to be run on top of the hour. so I am trying to skip the execution from script by checking top of the hour
In general, it's better to leave scheduling decisions to cron or other processes outside of the thing being scheduled. Use a cron schedule that runs your script or code every 10 minutes, in such a way that it avoids running on the hour: 10,20,30,40,50 * * * * my-command-here This is much more convenient than trying t...
how to identify top of the hour in a shell script
1,593,723,601,000
In my crontab , I set following bash function and applied it for my job. it is indicated to add timestamp to the log. adddate() { while IFS= read -r line; do printf '%s %s\n' "$(date)" "$line"; done } 30 06 * * * root $binPath/zsh/test.zsh | adddate 1>>$logPath/log.csv 2>>$errorLogPath/error.txt But ...
Cron doesn't accept shell functions, create a script like #!/bin/bash adddate() { while IFS= read -r line; do printf '%s %s\n' "$(date)" "$line"; done } $binPath/zsh/test.zsh | adddate 1>>$logPath/log.csv 2>>$errorLogPath/error.txt and put that in cron. (I'm assuming here that you used $binPath and $l...
bash function command not found in cronjob
1,593,723,601,000
I don't have MTA installed on my desktop. Whenever there is a problem with a cronjob script, I see this in my logs: CRON: (CRON) info (No MTA installed, discarding output) A script that was supposed to be run by cron generated an error, and cron wanted to send me the error per email. But I would like to see the erro...
You can use the logger subsystem. There are two variants, depending on whether you have systemd installed or not. With systemd - using systemd-cat echo This is a test with systemd-cat | systemd-cat -t mytest -p info This writes a message to the journal logger (see journalctl) and also through to the legacy system lo...
cron: send errors to syslog, instead of MTA
1,593,723,601,000
I'm writing a bash script which, among other things, will edit crontab on another server. The way I figured out how to do this is with: crontab -l | sed <stuff> | crontab - It does what I need it to do, but I'm still not sure how. What exactly does "crontab -" do? When I run it by itself from the shell, it takes over...
One syntax for crontab is crontab <file> Per Usage of dash (-) in place of a filename your usage of the - is to take stdin which in this case is the stdout coming from sed which is then feeding in to replace the <file> argument and replace the contents of cron instead of from the file you are giving it the stdin tha...
function of "crontab -"
1,593,723,601,000
I'm running FreeBSD 11.0-RELEASE. On default cron is using /usr/lib/sendmail to send user emails. How can I tell/set cron to use /bin/mail instead? FreeBSD is using the cron version from Paul Vixie, so the -m option sets the email receiver not what mailer to use. I downloaded the FreeBSD source code and tried the comm...
cron by default uses the value of the systemwide _PATH_SENDMAIL macro as the expansion of MAILCMD, the command to use to send messages generated by jobs. In order to use a different mail program, you need to modify the Makefile to define appropriate values for the MAILCMD and MAILARGS macros. The Makefile in the sourc...
Change cron default sendmail to mail
1,593,723,601,000
I have a cron job that is running twice an hour. It runs once at HH:00 and once at HH:45. This is strange because I tried to specify that it should run every 45 minutes as follows: */45 * * * * python my_job.py This works fine for other jobs I run every 5 minutes as well as jobs that run every 20 minutes. However, I w...
Your job runs on every minute that is a multiple of 45, i.e. whenever minute % 45 == 0. So it will run at hh:00 and hh:45. If it were an exact factor of 60, it would run at even-sized intervals. To make it run at 45-minute intervals, I think you will need three rules, one for each hour (mod 3). Although I haven't tri...
Cron job runs more often than I thought it should
1,593,723,601,000
I have a cron job that, among other things, does a recursive ls of a directory into a file. This gets compared to another file that I've created that, supposedly, contains an identical listing of the same directory. My problem is that, when I generate the version for comparison, I get the files listed in case-insens...
Sorting problems can be avoided by explicitly forcing applications to use a certain sort order. You can check the current locale by running locale instead of the program in question and compare the output of different call situations. The sort order can be forced by setting LC_COLLATE / LC_ALL within the command line:...
ls gives me different sort orders during a cron job
1,593,723,601,000
There is this thing in QuartzScheduler where we can say execute this in CST/BST/ or whatever timezone. This is also good when you want to execute some jobs in certain timezones and certain jobs in some other timezones. Is there something like that in crontab where we can specify the timezone, because I have been seein...
This depends on your distribution: some versions of Cron support this, others don't. For example, on Debian: LIMITATIONS The cron daemon runs with a defined timezone. It currently does not support per-user timezones. All the tasks: system's and user's will be run based on the configured timezone. Even if a user sp...
Is there anything in unix crontab to determine this should be executed in PST/CST standard time?
1,593,723,601,000
I want to set a personal crontab in another folder and executed. For example I want it in /home/project/tasks/crontab Like that it's easier to add/delete tasks. Thank you for your answers.
The cron daemon determines where your active crontab is stored. On my system (Ubuntu), and probably on yours, it's under /var/spool/cron/crontabs/. But you can maintain your crontab entries anywhere you like. Just remember to run crontab /home/project/tasks/crontab every time you update it. (I suppose you could set...
Crontab Change location
1,593,723,601,000
Given a crontab expression like "0 0/15 11-15 ? * MON-FRI", how is that parsed? I am correct in assuming the 11-15 does not mean "between 11 and 15" but "when the hour is 11-15, inclusive" - i.e. the expression will trigger every 15 minutes starting at 11:00 and ending at 15:45? Or will it end at 14:45? Or maybe 15:0...
You have too many fields in your example. The available fields in a cron job are: `min hour mday month wday command+args` The command in your example line would run on: The zero minute every 15 hours, starting at midnight (so midnight and 3pm) on the 11th/12th/13th/14th/15th of the month, invalid month field of ? ev...
crontab "0/15" minutes + "11-15" hour field: when does that end?
1,593,723,601,000
I have many computers and I ssh between them. I have a single cron file, which I manually type after into each computer. And when I change this cron file, I have to manually ssh into each computer to update its cron accordingly. Is there any way to have each computers cron, become a function of this file? That way I c...
This answer is assuming that you are concerned with the crontab of a particular user, myuser. A cron job re-reading the cron schedules from a file (crontab crontab.txt) would be fairly easy to set up, but you could do that from ssh directly with ssh myuser@remote crontab - <crontab.txt where crontab.txt is stored loc...
Multi computer cron
1,593,723,601,000
I have a server that I am hosting at home using a residential ISP that issues public IP addresses via DHCP--that is to say, I don't always get the same IP back when my DCHP lease renews. I created a bash script to check whether my public IP has changed, and to e-mail me the new IP address if it has changed. The "curre...
The reason that /etc/cron.hourly/public-ip-monitor.sh didn't work is because the hourly cron entries are initiated via run-parts in the /etc/crontab file: 01 * * * * root cd / && run-parts --report /etc/cron.hourly run-parts has certain rules about what it runs: run-parts runs all the executable files named within c...
Debian 11 (bullseye): user cron jobs not running
1,593,723,601,000
I created update.sh as following: #!/bin/bash sudo apt-get update sudo apt-get upgrade echo "Updated Successfully! and created the following crontab job to run this script every hour: 0 * * * * bash /home/ubuntu/update.sh >> /home/ubuntu/cron_test.txt but only the log file entries of echo com...
You're facing a couple of issues, both rooted in the fact that WSL doesn't run Systemd by default (or easily). I go into detail a bit on this in an Ask Ubuntu answer and another on Super User, so I'm not going to deep into that again here. But without Systemd: unattended-upgrades, which was suggested in the comments...
How do I execute a simple "apt-get update and upgrade" script using a crontab job?
1,593,723,601,000
I have a cron job that can fail periodically when resources are not available. Waiting awhile and trying again is the best way to handle such failures. What is the best way to do this? Have the failing script reschedule itself using at? Is there a better method? Perhaps something that already has such retry infra...
Had a need to keep retrying until a service was available, and so built a dedicated tool to do just this. https://github.com/minfrin/retry ~$ retry --until=success -- false retry: 'false' returned 1, backing off for 10 seconds and trying again... retry: 'false' returned 1, backing off for 10 seconds and trying again.....
Retry cron job on failure
1,593,723,601,000
Here is the job, intended to run every 15 minutes between 7AM and 7PM: */15 07-19 * * * /home/max/bashScripts/rsyncMe >/dev/null 2>&1 The job is running every 15 minutes every hour instead, i.e., it runs from midnight to 23:45. The job itself completes in under 5 minutes each time it is started. The OS is Debian-Bust...
The valid hours range is 0-23, so you should use */15 7-18 * * * to run every 15 minutes from 07:00 (first run) to 18:45 (last run) every day. The leading zero for the hour range (07) was the cause for the hour field to be assumed as *. I tested (cronie-1.5.1-lp151.4.6.1.x86_64 on suse) that the behaviour is same to...
cron job for hour=7-19 runs every hour instead
1,593,723,601,000
The crontab(5) manual says: 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 (see ``Note'' below). cron(8) examines cron entries once every minute. The time a...
As drewbenn commented, you missed ‘see “Note” below’. Note: The day of a command's execution can be specified in the following two fields — 'day of month', and 'day of week'. If both fields are restricted (i.e., do not contain the "*" character), the command will be run when either field matches the current time. 0...
Why does @weekly work as it does? Mistake in manual?
1,593,723,601,000
I have a script that scans a folder for all .mp3 files and creates an index. Next it waits 5s otherwise it doesn't work correctly. Lastly, it removes bad characters from the song names. I have this running automatically with sudo crontab: #!/bin/bash #Creates index file. find /var/www/html/uploads/Music/ -name '*.mp3...
It is likely because you run the commands in a pipeline. Each part of a pipeline is started at the same time and run concurrently with the other parts of the same pipeline. This means that the find command starts at exactly the same time as the sed command. It is only data passed through the pipeline, from the stand...
Why does this script output corrupt files when run automatically with crontab?
1,593,723,601,000
Before some days I wrote a script and put it somewhere to get it started automatically on booting on my raspberry with wheezy. ps -ax gives me: 2041 ? S 0:00 /usr/sbin/apache2 -k start 2064 ? Ss 0:00 /usr/sbin/cron 2067 ? S 0:00 /USR/SBIN/CRON 2068 ? S 0:00 /USR/SBIN/...
What started this process? You can use ps to find the parent of each process, either by adding -l (ps -axl) to give "long" output, or by specifically requesting the ppid: ps -o ppid 2074 PPID 2072 Repeat for 2072 to see what started that (probably CRON). Why two processes? cron passes each command to a shell. From...
From where is my script started on reboot
1,593,723,601,000
I have a shell script which, when run as root, performs various tasks to prepare a Debian (9/stretch) server for running a web application. Amongst the tasks that the script does is append cronjob lines to the crontab files for root and www-data (in /var/spool/cron/crontabs/), using cat and heredoc text. Each cronjob...
Rather than manipulate a individual crontab I'd opt to drop snippets of crontab functionality in /etc/cron* directories based. This seems easier to manage in the sense that all that's required is the creation/deletion of files from whatever /etc/cron* directory you need/want the snippet to run under: $ ls -ld /etc/cr...
Adding/removing jobs in Debian crontab files?
1,593,723,601,000
cron can be used to schedule running a program once in a while. But it seems to be not specific to an existing shell process. If I have a script which accesses the state of a specific bash process (e.g. to access the output of running jobs and dirs in the shell by source the script), how can I schedule its running in ...
Not entirely sure what you're after, but you can kick off a background job that does something and then waits X seconds, before repeating. Example ( while : ; do echo hello ; sleep 10 ; done ) &
Can I schedule running a script inside a particular shell process once in a while?
1,593,723,601,000
I want to run a command 7 to 24 o'clock every two minutes and 24 to the next day 7 o'clock every 10 minutes. I write */2 7-24 * * * command */10 24-7 * * * command But crontab tells me it has problem.So how to fix it? Thank you!
Midnight is 0, not 24. Furthermore, each column works independently, so 7-23 means “whenever the hour part of the time is between 7 and 23 inclusive”, not “between 7:00 and 23:00”. So use 7-23 for “7:00 till midnight” and 0-6 for “midnight till 7:00”. */2 7-23 * * * command */10 0-6 * * * command
How to write this schedule in crontab?
1,593,723,601,000
I add the following script line to the red-hat crontab, script should run on Saturday in 5:00 in the morning. In order to run the script /var/scripts/PLW.pl every Saturday at 05:00 morning. I want to check the exit status from the script. my question : is it possible to add in the crontab after the script line the som...
You can do something like, 0 0 * * 5 /usr/bin/python /var/scripts/PLW.pl && /bin/bash /path/to/run_once.bash Note : && /bin/bash /path/to/run_once.bash will only run if previous command run successfully. So instead of using exit code, you can use &&'s inbuilt functionality.
How to use exit status in crontab
1,593,723,601,000
I have a script that looks like this: #!/bin/bash D=~/brew\ update num=$(ls "$D" | cut -d ' ' -f 2 | sort -nr | head -1) num=$(( num + 1 )) script -q "$D/brew_update $num" brew update This script always works, but when I start it with cron 0 */5 * * * ~/bin/brewupdate2, it says this in a file in /var/mail ^Dscript...
D=~/brew\ update # the above will never work unless you start script as you # say you are user fred, this full path will always work D=/home/fred/brew\ update Cron works with different permissions and PATH than user, in other words cron basically is its own user (root), with its own PATH etc. Don't use ~/, that r...
Script usually works, but not with cron
1,593,723,601,000
I want to run sudo airodump-ng -w myfile every ten minutes or so, for m minutes. It does not matter if the running time shifts (that it, if it runs m minutes later each time). Notice that this is a monitoring program, which won't just output and exit. I suppose the solution for this one question is also valid for si...
Don't use pkill. Instead, run your app under the timeout command from the coreutils package: */10 * * * * timeout 5m airodump-ng mon0 -w myfile (Where here 5m means to run for 5 minutes.) Use --signal if you need something other than TERM.
Run and stop a monitoring command as sudo for s seconds every m minutes
1,593,723,601,000
I have several running processes which is started by a shell, but I don't want them to run during 08:00am - 20:00pm for each day because they are really bandwidth-consuming, so , I have to suspend them during that period of time instead of killing them directly because killing them will cause some problems.So , my wor...
You can use word notation for more readability : kill -STOP <PID> # pause kill -CONT <PID> # continue working Check man 7 signal
How to suspend a process for a certain period of time?
1,593,723,601,000
How would I set a script to execute on every Tuesday and Thursday at 11:50am? I've been looking at the at command, but I can't conceive how to use it the way I need to from its man page.
at is excellent tool for one-off commands. To run a program repetitively at the same times, however, the right tool is cron. Run crontab -e. It will open an editor. Add this line and save the file: 50 11 * * 2,4 /path/to/script This will run /path/to/script every Tuesday and Thursday at 11:50am. crontab runs pro...
How to execute recurring Bash script at specific times?
1,593,723,601,000
I checked the crontab set by the hosting company and they have this: 0 * * * * /usr/bin/php /www/sites/[domain.com]/files/html/shell/indexer.php reindexall Does this cron run constantly or once at midnight?
midnight is 0 0 * * * /usr/bin/php /www/sites/[domain.com]/files/html/shell/indexer.php reindexall your current crontab runs every full hour. For more info see e.g. this
Incorrect cron for midnight?
1,398,796,996,000
I have a cron entry that runs every 30 minutes - */30 * * * * /home/myuser/myscripts.sh How to set this up such that it runs exactly at 30 minute intervals but also exactly at (for example) 3:00 PM, 3:30 PM, 4:00 PM, 4:30 PM and so on. So I'm not only interested in the 30 minute interval but also the time being cl...
You can specify 0,30 * * * * /home/myuser/myscript.sh although I was always under the impression this would be the same as */30 * ..... But I have never used anything that had to be on the minute like that, just at a regular interval (*/5 * ....)
How to set up a cron entry that runs at 00 and 30 after the hour?
1,398,796,996,000
I have a root cron task that runs every day. But I want to allow normal users to request that it run immediately, if they so wish. It is a harmless process and it can run as often as needed and these normal users are actually trusted users. But I don't want to give these normal users any special permissions. Can I al...
As variant - create a script (added to crontab) and allow to execute without password https://askubuntu.com/questions/155791/how-do-i-sudo-a-command-in-a-script-without-being-asked-for-a-password
How can a normal user trigger a root cron task to execute immediately, without delay?
1,398,796,996,000
How can I use Crontab in Linux specifically for a Java program? I want to run a MIS Script. How can I crontab it and what should the path be?
Assuming this Java application is a console based app there is nothing inherently special you need to do just because it's a Java application. If you have a Java .class file, run the application like so: $ java HelloWorld If you have a .jar file, run the applicaiton like so: $ java -jar myapp.jar Cron job To make ei...
How to use Crontab for a java file in linux
1,398,796,996,000
The issue I currently have is someone has created a crontab process to run on a RHEL 5 box, yet has not left me any privileged user information. How can I execute this cron job that was setup to run as user foo when I do not have root access? Also of note this is a non-standard cron job insofar as it is run at arbit...
Invoking crontab -e when logged in as the specific user will open up that user's crontab file. Edits can be made from that point forward.
Location of crontab job created by non-privileged user
1,398,796,996,000
I think I'm missing something. I've set up some crontabs to handle rsyncs over ssh in my office to handle some backups, but they don't seem to be running OR logging, for that matter. Am I missing something? Here are my crontabs: 0 2 * * * idealm /usr/bin/local/rsync -avz --rsync-path=/usr/bin/rsync -e ssh /Ideal\ Mach...
First try some simple cronjobs and build from here: 0 12 * * * user echo 'Hello, World!' >> /tmp/test.log 2>&1 1 12 * * * user ssh anotheruser@anotherhost ls >> /tmp/test.log 2>&1 2 12 * * * user rsync -e ssh anotheruser@anotherhost:/path/to/small/dir /tmp/test-dir >> /tmp/test.log 2>&1 Avoid using too many options a...
Cron: My crontabs don't seem to be doing anything at all
1,398,796,996,000
I have to following cron script that runs daily. As you should be able to see from the code, it outputs the results from reflector to /etc/pacman.d/mirrorlist. $ cat /etc/cron.daily/update-mirrorlist #!/bin/bash reflector -l 5 -r -o /etc/pacman.d/mirrorlist Sometimes, reflector outputs a empty file and thus a invali...
It's a good idea to first accumulate the data, then move it into place. That way the target file will always be valid, even while the data accumulator program is running. set -e target=/etc/pacman.d/mirrorlist reflector -l 5 -r -o "$target.tmp" mv -f -- "$target.tmp" "$target" If reflector does not properly report er...
Stop cron script from destroying my mirrorlist with invalid data
1,398,796,996,000
It seems like an no brainer question, but i did not manage to any real information. In my Ubuntu server i have created a custom /etc/cron.d config file, e.g. /etc/cron.d/MyCronTab, the reason I put all here is for ease of finding and they are easy to modify. Now I'm not going to put anything sensitive at all in these ...
It’s your file, you control its permissions — neither package updates nor the cron daemon itself will change them. As a general rule, while many files under /etc are provided by the system, /etc is the system administrator’s domain, and the system will preserve changes made there. Even changes made to system-provided ...
When you alter permissions of files in /etc/cron.d in Ubuntu, do they persist across updates?
1,398,796,996,000
This script works when executed with doas ./backup_cron_root.sh #!/usr/bin/bash /usr/bin/crontab -l> "/tmp/cron.$(whoami).$(hostname)" && /bin/date>>"/tmp/cron.$(whoami).$(hostname)" && /usr/bin/doas -u joanna /usr/bin/cp -f "/tmp/cron.$(whoami).$(hostname)" "/home/joanna/pCloudDrive/backups" && /usr/bin/rm "/tmp/cro...
The issue seems to be that you do not allow the root user to switch to the joanna user without a password in your doas configuration. You do this with the nopass option in the doas.conf file: permit nopass root (It makes little sense to stop the root user from using doas to change to other users, so I removed the as ...
Why doesn't this script succeed from crontab as it does when manually run?
1,398,796,996,000
My local time zone is not UTC; How do I make cron use UTC for it's schedule without changing time zone on the computer in other aspects?
You can set the timezone with the TZ environment variable. If your system is based on systemd, you thus may alter the cron.service file an set the variable for the service only. E.g. for Debian in /usr/lib/systemd/system/cron.service add Environment="TZ=UTC" in the [Service]-section after EnvironmentFile= has been re...
How do I make cron use UTC?
1,398,796,996,000
I have a Mac mini running macOS Monterey, and it has InfluxDB running in a Docker container. I'm trying to set up a nightly cronjob via a shell script I'm calling to back the data up, zip it, and only keep the seven most recent backups. The backing up part works perfectly regardless of whether I'm running it manually ...
So thanks to @muru's excellent questioning, it turns out this was nothing to do with Cron and shell expansion at all, and was instead a case of the /usr/sbin/cron executable not having full disk access in System Preferences > Security & Privacy > Privacy. I unlocked the preference pane, went into "Full Disk Access", c...
Wildcard expansion doesn't happen when Bash script invoked from cron under macOS
1,398,796,996,000
I'm newbie making cronjobs with linux. My goal is to execute a python script in its own virtual enviroment. To do this I have made first a shell script called twitter.sh where its content is: source /home/josecarlos/Workspace/python/robot2-rss/venv/bin/activate python /home/josecarlos/Workspace/python/robot2-rss/main...
set a proper shell edit twitter.sh #!/bin/bash PATH=.... source /home/josecarlos/Workspace/python/robot2-rss/venv/bin/activate python /home/josecarlos/Workspace/python/robot2-rss/main.py R,1 be sure to set PATH. log result of command in crontab add login part */1 * * * * /home/josecarlos/Workspace/python/robot2-rss/...
Python: How to config crontab to run a script in a virtual environment
1,398,796,996,000
I'm trying to use crontab to check and re-run a long running script. I've created a script that checks the status and runs the long-running script if needed. I'm running the long running script with nohup to keep it running when I log out. The keep-alive script: #!/bin/bash BASE_PATH=~/scripts LOG_PATH=${BASE_PATH}/k...
There is no need for nohup when using crontab. Unless your systemd is configured to kill all your processes when you log out there is no interaction between your shell exiting and crontab running processes (or otherwise), and nohup will have no useful effect on that. Look at your local email (mail or mailx) and read t...
Use crontab to invoke nohup in script
1,398,796,996,000
I've just made a perfectly working Bash script that runs xprop(by a regular user and root): #!/bin/bash # time tracking BASH script # current time and date current_date=$(date --rfc-3339='seconds') # active window id window_id=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut --fields 2) # active window class wm_c...
You're missing the $DISPLAY environment variable. It is set by the first process that initializes your GUI session and then inherited by all its child processes. For a local X11 session, the value is normally :0. The $DISPLAY variable tells X11 applications how to contact the X server; the value :0 tells them to use ...
Running xprop in a crontab: "unable to open display"
1,398,796,996,000
I do not have much experience in Linux and would like some insight into whether there is a possibility to change a variable within a script before it is automatically started through a Cron Job. For example, that the variable VORDATE="04%2F15%2F2019" would be changed (automatically) to one week prior to today, presen...
I assume your cron job is going to run a bash script. Your script could use the date command to specify a relative date. A week in the past VORDATE=$(date -d "7 days ago") A week in the future VORDATE=$(date -d "7 days") man date for more information. edit: Howto format output You can format the output by adding a f...
Edit sh script before a cron job starts running
1,398,796,996,000
I have a situation where I need to delete from mailbox (eg. /var/mail/root) messages with specific Message-Id. Following code works only from console, but I have to do it without user interaction running from cron /etc/crontab. File: /tmp/clear_spam_test mutt -f /var/mail/root -e "set alias_file=/var/mail/root" -e "...
Same problem here. This mutt command seems to depend on a working terminal window that cron cannot build. At least for me it helped to start a virtual terminal using screen: screen -d -m mutt -f /var/mail/root -e "set alias_file=/var/mail/root" -e "set crypt_use_gpgme=no" -e "push <delete-pattern>[email protected]\n<...
CRON (no tty): Delete message with specific "Message-Id"
1,398,796,996,000
I wrote a small application, which runs etherwake. From bash it works fine and wakes up another PC. But if it is launched from crontab, then nothing happens. Has anyone encountered a similar problem and how to solve it? Note: Maybe it matters, that the app is written with Qt/C++, etherwake runs via QProcess and OS is...
I am replying to this message because I was struggling with the same issue. The problem seems to lie in the etherwake path. Crontab runs commands by default in /bin. But etherwake is located in sbin. /usr/sbin/etherwake So instead of doing: 00 06 * * * etherwake -i wlan0 00:11:22:33:44:55 The proper way is: 00 06 *...
Cron and etherwake on Raspbian
1,398,796,996,000
I'm working on a script that is supposed to execute on startup, but the problem is that the script requires some files that are on a shared drive that is automatically mounted via fstab and at the time of it's execution the drive isn't mounted yet. I've tried using cron @reboot and init.d route but they both execute t...
For that you have to run your script as a systemd unit (assuming you have systemd) where you could define dependency... If you want to stick with cron @reboot (what sounds the simple choice) you have to make your script a bit smarter (or start cron after fs mounts... what change I wouldn't suggest). Instead of a simpl...
fstab mounting time
1,398,796,996,000
I have an entry in my crontab file: 14 17 * * */2 python /home/pi/scripts/irrigate_5mins.py >/dev/null 2>&1 The intention is to run the command every other day, which is what the manpage (man 5 crontab) says is what */2 does. The actual quote from the manpage is: Steps are also permitted after an asterisk, so if you ...
By specifying */2 in the day-of-week field, you run on even days. Even days of the week are Mondays, Wednesdays, Fridays and Sundays. (Actually, these are the odd days, hmm, still...) If you want to run the job on slightly more regular intervals, use the day-of-month field instead (the third field). Note that on mon...
Why does my vixie cron entry to run every other day, actually run on consecutive days every 4th time?
1,398,796,996,000
I'm not in front of a testing environment right now but I desire to download a Bash script with curl and then load its content into crontab. The content as appears in Github raw document is for example: 0 0 * * * ... 0 0 * * 0 ... Is this code template looks okay to you? curl -O https://raw.githubusercontent.com/use...
curl outputs to stdout by default so curl URL is enough. And at least on macOS crontab needs a - to read from stdin so we end up with curl URL | crontab - Whether it is wise to load unverified data from an URL directly into Cron is another question though...
Piping content from Github into crontab
1,398,796,996,000
As an example, take the phpsessionclean schedule. The cron.d file for this looks like this: 09,39 * * * * root [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi It's saying if systemd doesn't exist on the system run the script /usr/lib/php/sessionclean. ...
You could be looking in the wrong place. Units can be in several places. $ systemctl cat systemd-tmpfiles-clean.service # /lib/systemd/system/systemd-tmpfiles-clean.service ... (you can also see a command here: $ systemctl status systemd-tmpfiles-clean.service ● systemd-tmpfiles-clean.service - Cleanup of Temporary ...
How to see what command is being run by a systemd .timer file?
1,398,796,996,000
I'm not able to redirect output of command into a file when ran with cronjob [root@mail /]# crontab -l */1 * * * * /sbin/ausearch -i > /rummy [root@mail /]# cat /rummy It's weird that when I dont give -i option , I'm able to redirect it very well. [root@mail /]# crontab -l */1 * * * * /s...
The command does not produce output, but runs ok. You can see this because the file rummy got created. The ausearch utility seems to expect a "search criteria", and the empty output could be due to you not providing one. See the ausearch manual on your system for further information. After a bit of reading of the aus...
cronjob not redirecting output of command when used with option
1,398,796,996,000
I am trying to make something which records my public ip address in a database, every few minutes. I have already developed a web page which records the viewer's ip whenever loaded. I would like to set up a cron job which will periodically load the page in the background. I know how to set up the cron job, but I don't...
Presumably, the page was developed so that the user agent doesn’t actually have to be a browser. If this is the case, you can simply use the curl command to fetch the page. If you’re running it as a cron job, you don’t want the command to print any output. To do this use, the --silent option for curl and discard the H...
How to run a web page in the background?
1,398,796,996,000
A vision system program runs on a PC and I need it to be always running and on top, But sometimes there may happen a problem in the program and terminate it. So I need a script to check if the program is not running and run it as well. I used cron job to the task, I wrote this cron job to run the script: */1 * * * * ...
Cron jobs aren't really suited to managing desktop applications. You'd be better off starting the application from a looping shell script; at its simplest #!/bin/sh cd /home/masoud/Desktop/vision3 while :; do ./vision; done That way whenever vision stops, it will be started again. You may want to plan an "exit strate...
Start a program using cron job
1,398,796,996,000
On my system, notify-send requires 3 enviorment variables to run, which are kept in a file which is generated automatically on logon: /home/anmol/.env_vars: DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-PwezoBTpF3 export DBUS_SESSION_BUS_ADDRESS XAUTHORITY=/home/anmol/.Xauthority export XAUTHORITY DISPLAY=:0 expo...
It is working after replacing * * * * * /home/anmol/display-notif.sh with * * * * * sudo -u anmol /home/anmol/display-notif.sh
notify-send from root cron
1,398,796,996,000
please advice how to set the crontab in linux to run a task each day at 23:00 at night and if someone know a shell script that we can run in the linux that can help us to set acrontab syntax
If you read the cron documentations you will see that you need to use command crontab -e and enter record like: 0 23 * * * /path/to/executable
linux crontab + how to set crontab at 23:00
1,398,796,996,000
I want my cron job to run every hour, every day except Friday when I don't want it to run at all between the hours of 2am-9am (but hourly outside of this timeframe). Ideally, I'd like to have this in one line/one cron job. What I have so far is 2 lines (and I'm not 100% sure it is correct): 0 0 * * 0,1,2,3,4,6 script....
The format seems to be correct (after correction applied posted in the comment above). Are there some special restrictions for having everything in a single line? In case you need to have everything in a single line, I would suggest to change the shell script to avoid Fridays 2-9am, eg #!/bin/bash # THIS CODE IS NOT ...
Cron Job Hourly Except Certain Time Frame on Friday
1,398,796,996,000
I have set up a cron job that should execute hdparm -y /dev/sda >> /var/log/diskspindown.log 2>&1 When testing it running it via "Run selected task" it executes fine and logs /dev/sda: issuing standby command but when executed on schedule it doesn't work and logs /bin/sh: 1: hdparm: not found
Try to use full path (which hdparm). Cron does not have to have all the paths set up.
Gnome Schedule cannot run hdparm
1,398,796,996,000
i have a python script when i launch my script all it's ok but when i lauchn my scrypt under crontab i have this errors: .. 2015-04-24 14:36:02,163 ERROR Problème dans le module importData[Errno 2] No such file or directory: '/opt/scripts/stockvo.json' .. My script py: #!/usr/bin/env python # -*- coding:...
To resolve my problem I added these lines to crontab PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/opt/scripts 0 4 * * * /opt/scripts/importData.py thank you to val0x00ff who gave me the solution
Script not run with cron [closed]
1,398,796,996,000
I tried to schedule my first cron job as follows: crontab -e The file had some comments at the top, and on the first line after those, I put * * * * * date I expected the date and time to be printed out every minute, but nothing happens on the terminal. Is the output getting sent elsewhere, or is the cron job not r...
From the cron man page: When executing commands, any output is mailed to the owner of the crontab (or to the user named in the MAILTO environment variable in the crontab, if such exists). The children copies of cron running these processes have their name coerced to uppercase, as will be seen in the syslog an...
Cron job gives no output
1,398,796,996,000
Say I have the following in my crontab: * * * * * command1 -option A; command2; command3; etc. I would like cron to run the commands I have in that line with a specific shell. How can I do that? I know that I could technically put these commands in a file, add the corresponding shebang, and then just ask cron to run...
You can change your cron string to: * * * * * /bin/sh commannd1..; /bin/tcsh command2... ; /bin/zsh command3 This is the more extreme case. But you can prefix the name of the specific shell before the commands. Another option is echo all the commands to the specific shell * * * * * echo 'comand1...;comma...
Switching shells for one cron job
1,398,796,996,000
I have two servers that are synchronized with rsync, one is the failover server of the other, so they both have the same name. Now root mails that are sent to my other account are all named from root <[email protected]> so I have no easy way of distinguishing from which server they are coming. Is there a way of chang...
Change the 'From' text by editing /etc/passwd to receive mail from 'root at failover' instead of just 'root'. chfn -f 'root at failover' root source: https://wiki.archlinux.org/index.php/SSMTP
change the name for root mails from cron
1,398,796,996,000
So I have a python script that pulls down git/svn/p4 repositories and does some writing to a database. I'm simply trying to automate the running of this script and based from what I see in syslog it is being run, even the file I tried piping the output to is being created however the file is empty. Here is the cron jo...
So it turns out the problem was with environment variables that the Python script needed, and it was so early on in the script that it broke the script before it even output anything. Cron does not have a regular environment. Furthermore ssh passwords were required for pulling git repos which i was able to solve by us...
Cron job not behaving as expected
1,398,796,996,000
I had a simple Qt program, when running, it shows a simple window with a countdown timer. If you might be interested in the code, please see here. I had crontab line * * * * * /home/my-user-name/Documents/bin/program When executing the comment /home/my-user-name/Documents/bin/program, the program runs correctly. Bu...
The problem is that cron runs in a text environment. There are a few different approaches for that, depending on what your machine is running. set a display variable: * * * * * DISPLAY=:0.0 /home/my-user-name/Documents/bin/program set up a password-less ssh key-pair and do * * * * * /usr/bin/ssh -y user@localhost /h...
Qt program not invoked by cron
1,398,796,996,000
Almost 3 weeks that, in my downtime, I try to find out where the files cron.allow & cron.deny are located in debian7 distro. No way, it seems that by default they are not in the system. 'Just' for hardening purposes, I would have those files available in my system. My question is actually if I can just touch them and...
From the manual man 1 crontab: If the /etc/cron.allow file exists, then you must be listed (one user per line) therein in order to be allowed to use this command. If the /etc/cron.allow file does not exist but the /etc/cron.deny file does exist, then you must not be listed in the /etc/cron.deny file in order to use ...
debian7 cron.allow & cron.deny files
1,398,796,996,000
So I've spent around 2-3 hours now and some times researching, I found several of the same responses online but none seem to work! I'm trying to execute a PHP script every minute (as a test), but it doesn't work. I honestly don't see what's wrong with that script. So I've went to check the logs and I get this; Ma...
You seem to have some version of cron which expects a user-name parameter before the command. It is even in the header, just a bit concealed: * * * * * <user-name> <command to be executed> Try this (replace root with whatever user php/apache runs at): * * * * * root /usr/bin/php /var/www/html/directory/file.php ...
Executing PHP with CronJobs in CentOS 6.4 not working?
1,398,796,996,000
Being able to put a script in /etc/cron.daily is really nice because I can do it easily from a configuration management system or a package. However, my understanding is that all the entries in /etc/cron.daily will run sequentially. How can I make a script in /etc/cron.daily not hold up the other tasks? Would somet...
Yes, if you background the process in the script, the next one will be started. Scripts in /etc/cron.daily are run by run-parts (from man cron): Support for /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly and /etc/cron.monthly is provided in Debian through the default setting of the /etc/crontab file...
Running cron.daily in parallel
1,398,796,996,000
As root, I've setup a crontab rule that launches vpnc everyday early in the morning (before I arrive at my workplace). But it often occurs that the vpn stopped mid day. As a result, I have to sudo vpnc ... in order to relaunch the background process. How to make the vpnc respawn automatically? Maybe initab respawn rul...
You could put a simple cron script together that would monitor to see if the vpnc process is still up. If not, then run it. #!/bin/bash if [ "$(pidof vpnc)" ]; then echo "restart" ..run vpnc here.. else echo "running" ..do nothing.. fi Once you've created this script, call it /etc/cron.d/vpnc_checker.bash ...
How to respawn vpnc when it stops?
1,398,796,996,000
I would like to keep my download folder sorted. My goal is to have the files of the current week in the download folder, and the older files in a folder named after week number and year (eg 2013.09, lexicographically sortable) of the creation date of these files. I only want this to apply to the files and folders foun...
Set the crontab as: @reboot the-script 0 0 * * 1 the-script 0 0 1 1 * the-script To have it done on Mondays and at each boot. And in the-script, check if it's already been done. (if using the %W for the week number, you need also to do it on the first of January (thanks Gilles), not if using the ISO 8061 week number ...
How to run a script as soon as the week number changes?
1,398,796,996,000
I have a fairly simple shell script (foo.sh) that looks like this: #!/bin/bash echo -n "$USER,$(date)," `binary -flags | sed -e '1,30d'`; exit 0; This script is supposed to prepare some output which will then be appended to a text file, like so: foo.sh >> data.csv When I run the above on a root prompt, it works fin...
You can't count on having the same environment in a program run via cron as when you run it interactively. There are two differences most likely to matter in this instance: The current working directory The PATH As jordanm commented above, one or both of these in combination is causing the script to not find your bi...
Why do I get different outputs when running my shellscript manually from when I run it with cron? [duplicate]
1,370,511,561,000
I would like to give out a warning If cron is not running or if a certain cronjob is not set in crontab on my server. Is this possible to check with php?
You can parse the output of crontab -l to see if a particular crontab entry is present or not. As for if cron is running or not, you can parse the output of a ps -eaf command to see if crond is running or not. $ ps -eaf|grep [c]rond root 1705 1 0 May27 ? 00:00:03 crond The output from crontab -l woul...
How can I check if my cronjob is runnning on my server via PHP?
1,370,511,561,000
I'm running a Python program on my Linux server, and depending on some external data it has to run again at xx minutes or hours from now. So let's say it runs at 6 AM, and then it has to run again at 7 AM. Then, at 7AM, it checks some things and it has to run again at 15:45, and then the next day at 2.05AM, and then t...
crontab should be used for jobs that you want to have repeated regularly. An alternative is at. With this utility you can schedule jobs that you want to execute only once, but in the future. From within the python-script, you should be able to add a command to the queue of at. The link page together with the man-page ...
How can I schedule a python program to run from another python program?
1,370,511,561,000
I have made a mistake, I have edited /etc/crontab via copy and paste. And now those crontab entries are not working. [root@process ~]# cat /etc/crontab 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.dail...
You don't say which distro or version of the cron daemon you are running, but it is likely that your cron maintains system crontab files (/etc/crontab) and also per-user crontab files. The file that you are seeing when you run crontab -l (as root) is probably /var/spool/cron/crontabs/root which is where you want to ma...
/etc/crontab edited via copy and paste, how to revert back?
1,370,511,561,000
From a server hosted in Poland (UTC +01:00), is there a way I can consistently have a crontab entry run at 9am New York time (UTC -05:00)? For me this wasn't trivial since the daylight saving time ended last Sunday in Poland, so jobs that I have scheduled to run at 15:00 their local time most of the year are late this...
Okay, since altering the TZ env for date does seem to call up the correct current time in Ubuntu, this is at least a workaround (the one I was trying not to rely on): SHELL=/bin/bash 0 14 * * 1-5 [ $[10#$(date +\%H) - 10#$(TZ=":US/Eastern" date +\%H)] == 5 ] || sleep 3600; w;df So this aims to run w;df at 9am ET Mo...
crontab and DST disagreement with different timezone
1,370,511,561,000
I need to run a command once, but only once, per day, until it succeeds. Continuous uptime cannot be expected, and program success cannot be guaranteed. This program requires network access, but not every time I start my computer with network access. My program will exit with, e.g -1 unless it succeed ( which returns ...
Use a shell to provide this. For example, create a script with something like the following: #!/bin/sh # Check to see if this is already running from some other day mkdir /tmp/lock || exit 1 while ! command-to-execute-until-succeed; do # Wait 30 seconds between successive runs of the command sleep 30 done rmdi...
How do I run a program only once per day, while accounting for variable uptime and possible failure of program?
1,370,511,561,000
I have a problem, some user ,and I'm not sure who, on one of my servers wrote a cronjob that executes every night at midnight. The cronjob creates a sql dump of a database which is then grabbed by another server and gzipped. The problem that I'm experiencing is that once that has occurred the file on the local system ...
On solaris at least, look in /var/spool/cron/crontabs
Need to find a cronjob
1,370,511,561,000
I wrote a combination .sh and .exp scripts that: activate vpn connection connect to remote server download some files from server deactivate vpn connection This scripts should run on schedule. I use nmcli for activate and deactivate connections. If I run scripts manually it work correctly, but if I run this scripts ...
Thanks @woodin for advice (after 8 months I returned to this question)! What I did. Firstly I compared outputs of nmcli general permissions launched from terminal and from cron. From terminal (permissions for me) PERMISSION VALUE org.freedesktop.NetworkManager.ch...
nmcli Error: Connection activation failed: Not authorized to control networking
1,370,511,561,000
I'm testing to set up some backup. I set up my crontab to run every minute. I have a disk that is mounted on machine2 that I will upload the backup to. I'm compressing the content of folder /home/user/important to important.tar.gz and moving the tar.gz file to machine2's /mnt/backup2 folder. cron tab entry: * * * * *...
It's hard to know what's the real problem here, but here a couples things you could try: Put this one-liner in a script, chmod -x it and use this in the crontab This will allow you more control over whatever is happening (eg: set -x, etc). Enable debugging output to see what is causing your crontab entry to not wor...
Command works in terminal, but not in crontab
1,370,511,561,000
I'm making a small script in which I make several calls to Zenity. Executing the script manually or executing the commands from the terminal works properly. However, when I run them from Cron they give me problems. To test it, I have put in crontab two commands: export DISPLAY=:0 && zenity --info --text "Window test" ...
I added this to my user's crontab; this has been tested with python (notify2 library) and zenity: DISPLAY=":0.0" XAUTHORITY="/home/my_username/.Xauthority" XDG_RUNTIME_DIR="/run/user/1000" DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
Do Zenity system tray notifications not work with Cron?
1,370,511,561,000
Using Mac OSX version 10.14.x Want to run a Python script every 5 minutes. Created a shell script, check.sh and marked it executable so that it runs the Python script as shown below. /usr/bin/python resolve.py Created a crontab entry using crontab -e command as shown below. 5 * * * * ./check.sh It is listed successf...
Your cron job is scheduled to execute every hour 5 minutes after the hour. If you want it to run every 5 minutes change it to: */5 * * * * ./check.sh
Cron tasks not executing on Mac OSX
1,370,511,561,000
I have this incrontab, which is monitoring the master Directory to check if the event occurs where a new file is placed here ... and run the php file. /var/www/html/docs/int/master IN_MOVE php /var/www/html/shscript/work.php I have a crontab that runs every one minute, and invokes the execution of a .sh file, the con...
the result script to do: /var/www/html/docs/int/master IN_CLOSE_WRITE php /var/www/html/shscript/work.php Script file to copy from the master repository to the Work directory and after that to move it to processed #!/bin/sh cd /mnt/test1/int/master find . -maxdepth 1 -type f -exec bash -c ' for item do cp $item /...
incrontab is not triggering with end of cron sh invokes
1,370,511,561,000
I'm running a Raspberry Pi Model 2B with Raspbian Stretch (Debian). I have a UI-application (chromium-browser, started via /home/pi/.config/lxsession/LXDE-pi/autostart) and a script started via cron, both of which depend on the actual current time being set when they start (or I'd have to put some ugly hacks in the co...
So what I ended up doing is implementing some rudimentary time jump recognition in the script and the application.
Delay further startup until time is synced
1,370,511,561,000
I have a shell script that works fine when run manually, but fails when run through the crontab. The script essentially does as follows: Python script to get audio data and pipe to stdout | ffmpeg the data from stdin and pipe to stdout | stream the data from stdin When run through crontab the streaming fails, complai...
As it turns out, the issue really was the python file and cron, but not an issue with file descriptors (stdin/stdout) in the way I had expected. Rather, as per this answer having a line asking for user input while running through cron was causing the issue. I solved the issue by removing the request for user input as...
Shell script with pipes not working in crontab
1,370,511,561,000
I use the following /etc/crontab code to create daily backups of my database in limit of the last 30 days: 0 8 * * * mysqldump -u root -PASSWORD --all-databases > /root/backups/mysql/db.sql 1 8 * * * zip /root/backups/mysql/db-$(date +\%F-\%T-).sql.zip /root/backups/mysql/db.sql 2 8 * * * rm /root/backups/mysql/db...
Create a script to do the complete dump, backup and cleanup. Schedule the script. Additionally, the password to mysql may also be stored in a protected file and does not need to be given on the command line. MySQL has a "End-User Guidelines for Password Security" document that you may want to consult. To summarize t...
Making a cron-scheduled database backup (dump) without exposing the password in /etc/crontab
1,370,511,561,000
For a project I want to use wget in a cron to download a data file. In the wget statement, a start- and enddate have to be defined in the following format: wget --post-data="stns=235&vars=TEMP&start=YYYYMMDDHH&end=YYYYMMDDHH" Since I want it to be done by a cron job, I would like the start- and enddate to be set au...
Within a cron job, % is special and must be escaped. Also, backquote syntax is best avoided. I would suggest something like the following: wget --post-data="start=$(date ... +\%Y\%m\%d\%H)&end=$(date ... +\%Y\%m\%d\%H)&..."
Using date variable with wget --post-data [duplicate]
1,370,511,561,000
I set up two cron tasks to mute my desktop's audio at night and then unmute it in the morning (so that emails and other notifications don't wake me up): lumpy@cheetoserver:~$ crontab -e # At 10:15 PM every night, mute the volume 15 22 * * * /usr/bin/amixer -q set Master mute # At 7AM every morning, unmute the volume...
I found other posts by people having exactly the same issue. The problem seems to be that the cron job runs without the necessary context, and adding export DISPLAY=:0 to each task is the solution: lumpy@cheetoserver:~$ crontab -e # At 10:15 PM every night, mute the volume 15 22 * * * export DISPLAY=:0 && /usr/bin/am...
cron task to unmute my audio isn't working
1,370,511,561,000
Basically I want to create a directory at some fixed time and after exactly five minutes, I want to create a text file in that directory. I tried this code but it didn't work 6 13 * * * /usr/bin/mkdir /qwerty /usr/bin/touch file1
Here is the command you asked cron to run: /usr/bin/mkdir /qwerty /usr/bin/touch file1 This calls mkdir with tree parameters: /qwerty, /usr/bin/touch, and file1. So, mkdir will attempt to create those as directories. You probably meant to run those as two separate commands: 6 13 * * * /usr/bin/mkdir /qwerty 11 13 * ...
How can I create a directory using crontab and after five minutes create a txt file inside that directory?
1,370,511,561,000
I want to run a bash script say every 5 minutes, with a predefined argument according to a cycle. For example, I want to use as the argument 1, 2, 5, 10, 15, 50, 15, 10, 5, 2, and then start the cycle again. Ideally, the arguments are stored in a file or in the script where I can easily edit them, add or remove some,...
Probably the most effective and one of the more simpler ways to accomplish this would be to have the script handle keeping track of cycling the magic number rather than using arguments. Something like this: #!/bin/bash sequence=(1 2 5 10 15 50 15 10 5 2) if [[ -r /var/tmp/myjob.seq ]]; then seq="$(cat /var/tmp/myj...
How do I do a cron job with cyclical argument?
1,370,511,561,000
The reason I ask this is to save resources. I try to save automated cron tasks wherever I can. Say one installs CalmAV in an Ubuntu based, Apache server, via the command: apt-get update # apt-get install clamav How do you then set the program, through the terminal, to work in an all-manual mode, without any task bei...
For this specific task, you'd do dpkg-reconfigure -plow clamav-freshclam and select manual. Note however that freshclam which updates databases uses minuscule amount of resources (runs one per hour for less than a second if there are no updates), and that clamav with outdated databases is a big problem. So running u...
How to set ClamAV for manual-only work in Linux (no automatic cron tasks)
1,370,511,561,000
I'm stuck with the following (simple) problem : I want a script to be executed every 10 minutes. This script calls executable files. I use crontab and ksh on a AIX 5.3 system. The script makes use of relative paths, but changing the executable path to absolute didn't make any difference. So, after a few tries and this...
change your shell script to provide a full or relative path to the executable: ./executableFile ... In interactive use, you must either have . or the cardme/bin directory in your PATH: that will not be true in cron's environment.
Execution of a program called by a shell called by crontab returns code 127
1,370,511,561,000
In Linux (Mint / Ubuntu), I can create cronjobs for each user individually. Is there any way, I can find out the name of the user against whome the cronjob is running. I want to get the username of cronjob owner in a shell script which is going to cron'd...
Get the script's owner On any system with as stat that is compatible with modern GNU stat, the user ID of the owner of the script is: stat -c %u "$0" The user name of the owner of the script is: stat -c %U "$0" In general on linux, stat -c %U file returns the owner of file. We substitute in $0 because that variable...
Get owner / user of a cronjob
1,370,511,561,000
I've been having an issue where I'll see many instances of a particular process: /usr/sbin/sendmail -FCronDaemon -i -odi -oem -oi -t I've done a bit of reading and it seems like the processes are starting up to send out the stdout output of a cron job, but for some reason never terminate. There's one process per day,...
The issue wasn't rooted in sendmail at all. Using pstree, I was able to determine that there were many more processes that were also hanging, not terminating, and parented by crond. I looked through each of these processes and discovered that one process was doing something along the lines of cat /var/log/some_log_fil...
Accumulating sendmail processes
1,370,511,561,000
I'm trying to make a backup .sh script to zip my files and to protect the zip archive with a password. For that, I'm using the zip package (apt-get install zip) and there's an encryption option accessible via the -e parameter. How can I specify the password directly? After typing the command, I need to enter a passwor...
You can use the -P parameter to specify the password on the command line: zip -r -e -q -P myPasswordHere ~/var/backup/backup_`date +%Y_%m_%d-%H_%M` /var/www/ You can find this sort of thing out by looking at the manual page for the program in question: man zip
Using zip package for debian with password
1,370,511,561,000
I am new to Unix here. We have some mailboxes that are taking up an incredible amount of space and I'm trying to figure out a way to delete all mail that has been in the box for 30 days. Most of what I look up, deals with just one mailbox. I haven't done much in this area yet and any help would be greatly appreciated....
If you want to clear out all of the mailbox contents except maybe root and some other protected user, you can use something like this: for mbox in $(ls /var/spool/mail/*|grep -v -e root -e protecteduser);do >${mbox};done and schedule it in cron to run on the 1st day of each month with crontab -e insert the followin...
How would you build a cron that empties the mail in all mailboxes?
1,370,511,561,000
So, I could use the crontab command, with: 23 0 * ... but at 23:00 my laptop can be turned off, or hibernated. In that case I want a command to be executed as soon as it will be possible. How can I do that?
Use @reboot in addition to your timing (if your crond supports it): @reboot command 23 0 * * * command The obvious caveat is that if you boot your computer at 22:59 the command will run twice in very short order. Make sure the command can be run twice at the same time without one process stomping on the other.
How to schedule task to run everyday, if I don't know when the pc will be turned on?