date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,607,029,596,000
i have build a cronjob for a single user www-data user by using sudo -u www-data crontab -e i'm trying to find where this file is saved, i have looking in /etc/crontab but its not here, soe i can't find it right now but the crontab is saved and every thing runing as it shut but i need the path to make backups of my c...
Depending on your OS, try /var/spool/cron/. On debian its a little further, /var/spool/cron/crontabs/. Usually, this is mentioned in man crontab
Where is the users cronjob
1,607,029,596,000
I have a CentOS Server with 200 Wordpress sites and now I want to insert this line in every wp-config.php file: define('DISABLE_WP_CRON', true) I know there exists a "for ... do ... done" possibility, but really I never used this before and I don't want to break all the sites. Please, help me!
It would be something like this: for i in /path/to/*/wp-config.php; do echo "define('DISABLE_WP_CRON', true)" >>$i done Be sure to make backup before doing this!
Insert Line in Multiples Files
1,607,029,596,000
I set up to run notify-send every minute, $ crontab -l 1 * * * * /usr/bin/notify-send -t 0 "hello" Why does it not work? Do I need to restart OS after editing the crontab file? Does the following mean that cron is running? $ ps aux | grep -i cron root 1038 0.0 0.0 23660 2420 ? Ss Apr20 0:00 cron...
Your first problem is that you have the wrong syntax for running a job every minute: 1 * * * * /usr/bin/notify-send -t 0 "hello" The 1 in the first field means that the job runs only at 1 minute after each hour. Change it from 1 to *: * * * * * /usr/bin/notify-send -t 0 "hello" The second problem is that cron jobs r...
My cron job doesn't run
1,607,029,596,000
I am using Fedora 20, and want, eventually, to set up automatic backups. I managed a trial run on my previous Fedora 12 installation, but can't get started again. I am using zshell. I thought I would get going by scheduling a shell program to show a zenity window with a "Hello World" message every minute. The zenity c...
An application started via cron has no connected terminal or even X available. So there is nothing where your window can be displayed. To test such things use a file and append anything to this. Then you can look in the file (e.g. with tail -f) and see that the cron is running.
How do I do "Hello World" to try using cron
1,607,029,596,000
What would be my crontab entry for a command which I want to run every week. I don't want to run any command between 8 PM till 5 AM and any random day is fine. Similarly what would be my crontab entry for command which I want to run every three month, and also I don't want to run any command between 8 PM till 5 AM and...
crontab entry for every week (Monday at 3:10 pm): 10 15 * * 1 test -x /path/to/your/weekly/command && /path/to/your/weekly/command and every 3 months, on the 2nd of January, April, July, and October at 1:12 pm: 12 13 2 1,4,7,10 * test -x /path/to/your/quarterly/cmd && /path/to/your/quarterly/cmd This is for a norm...
crontab entry for a command to run every week and three months?
1,607,029,596,000
I'm really new on Linux and have no any previous experience on it. And I opened this account to ask this question. I need to install a cron job I've followed the short guide here. Well, I think it has been installed successfully. Because, when I type crontab -l, I see it in the result that Putty display. I'm using Pu...
Each user has their own scheduled tasks. If you go and pick your kid from school at 4pm every day, your neighbor doesn't also go and pick your kid at 4pm. Cron jobs can be registered by each user (in which case they run with that user's privileges) or at the system level (in which case they run as a user chosen by the...
How to set cron job for system
1,607,029,596,000
I have a script running every 5 mins with two exits in a condition clause. #!/bin/bash date=$(date +%Y) if [ $date -eq '2014' ] then echo "Current year is $date" exit 0 else echo "Current year is not $date" exit 2 fi How could I specify to only write a log when exit 2? Could this be possible in cronta...
To write your error to stderr use the 1>&2 redirect: echo "Current year is not $date" 1>&2 exit [number] is specifying a return code of [number]. See also: File Descriptors Standard Streams All About Redirection
Write log for a false statement of an if condition which returns exit 2
1,396,027,959,000
Im trying to use mergecap to merge 15 old pcap files in a folder. I tried to use FILES=($(find /mnt/md0/capture/DCN/ -maxdepth 1 -type f -name "*.pcap" -print0 | xargs -0 ls -lt | tail -15 | awk '{print $8}')) and use mergecap command as mergecap -w Merge.pcap ${FILES[@]} but the mergecap doesnt run when I put it ...
With zsh (again): mergecap -w Merge.pcap /mnt/md0/capture/DCN/(D.om[-15,-1]) Or with GNU tools: cd /mnt/md0/capture/DCN/ && find . -maxdepth 1 -name '*.pcap' ! -name Merge.pcap -type f -printf '%T@@%p\0' | tr '\0\n' '\n\0' | sort -n | head -n 15 | cut -d@ -f2- | tr '\0\n' '\n\0' | xargs -r...
using mergecap for set of files
1,396,027,959,000
Yes, I have read many, many documentations but I can't get it to work. I have a simple single php file which I want to run once or twice in a minute. My php file is called: cronjob_refresh.php and I'm using Ubuntu 12. After typing crontab -e I'm getting in terminal: root@cron:~# crontab -e no crontab for root - usi...
888 is the number of characters in the default Ubuntu crontab file (22 lines of information all commented out). Typing ^Z doesn't save anything it puts the job in the background - read up on job control. 888 */1 * * * * php /var/www/cronjob/cronjob_refresh.php ? ^Z [1]+ Stopped crontab -e You should ...
Ubuntu crontab php not working
1,396,027,959,000
My below cronjob is not working. What am I doing wrong here?? */5 * * * * /usr/bin/top -n1 | head -10 >>/tmp/load.txt
The top from procps on Linux at least needs the $TERM environment variable to know how to display things like reverse color and cursor positioning when not in batch mode So either run: top -bn1 | head Or: TERM=dumb top -n1 | head Or if you need the output suitable for any given terminal, specify it as TERM=my-termi...
top not working
1,396,027,959,000
If I have a script called teiid.sh set to run daily by a cron job. The scripts purpose is to initialize the startup of teiid. How would I make a call to test to see the if teiid.sh is working properly with cron, and not just performing endless actions or no action at all? Example: @daily * * * * /etc/init.d/teiid.sh ...
you can do 2 things.. check /var/log/cron to check if it's being executed add > /tmp/log 2>&1 to the end of the cron entry. then cat /tmp/log to check if the output is correct.
Testing Scripts
1,396,027,959,000
For past couple of days I have been observing weird processes in one of our server. Most of the time I see multiple instances of executable 10 and sometimes 4 and takes a lot of cpu resources. When examined this I have been seeing the process is started by cron right after starting a process with executable cpu_hu. W...
(Rewritten based on OP's comments) The cpu_hu seems to execute as user postgres, which suggests it might have been started by using a weakness in your PostgreSQL database engine or its configuration. Maybe your PostgreSQL database is accessible from the internet and your database admin password is nonexistent or weak?...
Possible Malware: Unable to track starting point
1,396,027,959,000
I’m on debian. I am calling a ffmpeg process to generate a mp3. this gets called from a php script using shell_exec. This works fine 99% of the time. Sometimes, the ffmpeg process doesn’t exit and I’m left with ffmpeg running for hours. I”m slowly tweaking the params and its happening less, but still crops up on occas...
You can use timeout that runs a command with a time limit. For example: timeout 2 yes Will echo 'y' for two seconds (it would go on forever otherwise).
How to detect if a process runs longer than X seconds, then do something with it?
1,396,027,959,000
I am having trouble getting my Java program to run from cron. I am able to recreate the problem, using a simple example, as explained below: In the file /path/to/javaenv.txt I define my CLASSPATH variable as follows: export CLASSPATH=\ "/path/to/dir1":\ "/path/to/dir2":\ "/path/to/dirn":\ "/path/to/jar1":\ "/path/to/...
There are a few issues in your cron schedule: The % character has a special meaning in crontabs, and must be escaped as \% if you want to use it as you would ordinary use it on the command line. See How can I execute `date` inside of a crontab job? The source command may not be supported by the shell that interpret...
CLASSPATH in crontab
1,396,027,959,000
I'm running a headless networkless raspberry pi zero to control some hardware**, and occasionally the time/date gets corrupted, maybe other things too. While it's not a perfect fix, rebooting the machine automatically would be an improvement over the status quo. Normally cron would be the extremely obvious choice here...
How can you detect large clock jumps? Linux maintains at least two internal system clocks: The "real time clock" commonly kept in sync with an NTP server The "monotonic clock" never goes backwards, just ticks forwards A jump back of approximately 4 years is very likely to be caused by something resetting the real ti...
How to make Linux reboot every 30 days even if the clock gets corrupted
1,396,027,959,000
I want to set up a cron task to automate a Python script. For example: Suppose we have the script in the desktop directory. #set to run at 7 am each day mkdir url1 cp newspaper.py url1 python newspaper.py URL How would I do this?
modify your script so it won't rely on relative paths. You can use cd in your script, but mkdir newdir will attempt to create that newdir in a folder you won't expect. Do cd /proper/path first or do mkdir /proper/path/newdir, and do not forget that all other file manipulation commands are also could be victims of rel...
Cron task to automate Python script
1,396,027,959,000
I'm running this as a cron job: ( export PATH='/usr/bin:/bin' && echo "$PATH" && wget "https://www.mahmansystems.com.au/WSDataFeed.asmx/DownLoad?CustomerCode=%2F&WithHeading=true&WithLongDescription=true&DataType=0" -O mahman_direct.zip ) && echo 'I reached the end' &>> /home/myparadise/public_html/wp-content/uploads/...
I had no idea about the % sign behaviour in cron environment. Escape as \% and it works. Ref 1: https://stackoverflow.com/a/1921266 Ref 2: Cron gotchas.
Command runs manually successfully, but fails quietly in cronjob
1,396,027,959,000
In one of my cronjobs, I have a long &&-chained command, at the end of which, I put 2>>/home/myparadise/public_html/wp-content/uploads/import/files/raytheon/raytheon_log_error.txt - indicating that I want any errors to go to the file raytheon_log_error.txt cd /home/myparadise/public_html/wp-content/uploads/import/file...
You could wrap the chain in a subshell or command group, and redirect the error stream of that: (cmd1 && cmd2 && cmd3) 2>>/path/to/errorfile or { cmd1 && cmd2 && cmd3; } 2>>/path/to/errorfile For example $ crontab -l | tail -1 * * * * * { date && touch /root/file && date; } 2>> ~/cron.log $ tail cron.log touch: can...
Log the error for a whole && chain of commands (in Cron jobs)
1,396,027,959,000
I have the below crontab entries $ crontab -l #Cron to auto restart app1 #Ansible: test1 #*/15 * * * * ansible-playbook /web/playbooks/automation/va_action.yml #Cron to auto restart app7 #Ansible: test7 */15 * * * * ansible-playbook /web/playbooks/automation7/va_action.yml | tee -a /web/playbooks/automation7/cron...
You can use awk to do all the work of processing the output of crontab -l. The idea is to ignore blank lines, capture the text associated with comment lines, and print out the captured text when you get other lines. You mention that you want only the second field, so we will only save that. crontab -l | awk '/^$/ { ne...
How to get one line above the enabled crontab entry
1,396,027,959,000
I have in my cron that auto starts a service inside a tmux if it detects that its not running. The rest of my bash script works, but if the tmux session doesn't exist, it throws an error. Which is why I added in "tmux new ENTER" below. But it still doesn't start tmux session. If I manually started the tmux session, th...
Use /usr/bin/tmux new-session -d -s ENTER and for good measure follow it up with /usr/bin/tmux detach -s ENTER. So your script would look like: /usr/bin/pkill -9 java /usr/bin/tmux new-session -d -s ENTER /usr/bin/tmux detach -s ENTER sleep 3 /usr/bin/tmux send-keys -t 0 "cd /home/xxx/bbb;./run.sh" ENTER e...
Run a tmux new session with cron, then run a command
1,396,027,959,000
CentOS9 Keeping in mind this question: https://serverfault.com/questions/1099284/centos-how-to-keep-previous-service-state-on-reboot It seems that it is not possible to achieve what I need. Is that correct? What I need - to run a script which stops a service, collects and zips logs, then updates OS and reboots (in cas...
You can use a "flag" file and an @reboot cron job: #!/bin/bash # flag file must exist across reboots flag="/tmp/myflagfile" # # if there is no $flag, this is the 1st time if [[ ! -f "$flag" ]] ; then touch "$flag" do_firsttime else rm "$flag" do_secondtime fi You can control behavior by creating (or not) the...
Can I run a script on reboot once?
1,396,027,959,000
I have a script to set mouse 3 button to scroll: #!/bin/bash xinput set-prop "PixArt USB Optical Mouse" "libinput Scroll Method Enabled" 0, 0, 1 xinput set-prop "PixArt USB Optical Mouse" "libinput Button Scrolling Button" 2 Which is working when I execute it manually: ./mouse3.sh But it does not set mousebutton 3 t...
In "Session and Startup" (Debian 11, xfce) I added an entry with a command that is just the path to the script:
Get script to execute at startup
1,396,027,959,000
I'm on Ubuntu Server 20.04 LTS and what I'm trying to do is to set the cron job for automysqlbackup utility. When I installed automysqlbackup I noticed that the cron.daily/automysqlbackup was created inside the etc folder. In the automysqlbackup file there are the following lines: #!/bin/sh test -x /usr/sbin/automysql...
Why do we need these and what do they do? #!/bin/sh specifies that the cron “script” runs with /bin/sh (it’s a normal shell script). This is a shebang. test -x /usr/sbin/automysqlbackup || exit 0 checks whether /usr/sbin/automysqlbackup exists and is executable; if it isn’t, it exits the script silently. This line i...
What do the following lines mean in /etc/cron.daily/automysqlbackup?
1,396,027,959,000
Just wondering the above. So far I've tried: export EDITOR=$(which nano) export SUDO_EDITOR=$(which nano) export VISUAL=$(which nano) in both ~/.bashrc and /root/.bashrc, as well as Defaults editor="/usr/bin/nano" in /etc/sudoers and then logging out and back in again. None of the above has worked. Any ideas?...
If you have export EDITOR=$(which nano) in your homes .bashrc, try sudo -E crontab -e. You become root through sudo, so no need to specify the root-user for crontab. The -E preserves your users environment.
openSUSE Tumbleweed: How do I get sudo crontab -u root -e to open the root crontab in nano instead of vi?
1,396,027,959,000
I have a problem with logs on my web server using apache (centos web panel) Because it is an API server, once in a few days, the domlogs directory of the server get big enough to crash the server (more than 100gb in logs), so I need to empty the file with the command root@local: cd /var/domlogs root@local: > logfile.l...
You could set up a crontab for the user ID that runs the apache process, or under the root id, where the crontab entry would be like: @daily cd /var/domlogs; > logfile.log You don't need to create a shell script for a simple task like this; just separate the commands with the ; character. The @daily is a GNU exte...
cronjob to empty a file in a directory
1,396,027,959,000
I have a strange issue with a cron-scheduled task using find which does two things: The first line should delete every night files older than 3 days starting with "read_" and end with ".gz". The second line should delete every minute files ending with ".gz.md5" older than 1 minute. 1 1 * * * find <path that defian...
Fact: at 01:01 the two jobs run concurrently. Hypothesis: the filesystem in question does not store file types in directory entries. Possible explanation At some point find needs to know the type of the file under investigation. An explicit -type test can be a reason, but even without it (and in some cases before it) ...
find finds files not matching iname filter
1,396,027,959,000
I have an Ubuntu 16.04 server and one of the crons has a major vulnerability which has been listed as a "Won't Fix" for 16.04, but was fixed in Ubuntu 20.04. I want to pull the patch down, but when I use sudo apt upgrade cron it tells me that it is the latest version (which probably makes sense since it is the latest ...
If your release doesn’t provide an update you’re interested in, your “best” option is typically to download the source package (specifically, the .dsc and related files), and rebuild the package locally. (See this answer for a brief example detailing how to rebuild a package.) However this does bring a number of risks...
How to upgrade a single broken package without upgrading the OS (Ubuntu)
1,396,027,959,000
Right now, I have a cron job that looks like this: */15 * * * * cp /home/server/server_log.txt /var/www/html/logs/`date "+\%d-\%b.txt"` >/dev/null 2>&1 It works perfectly. However, I want to modify it to only get data from /home/server/server_log.txt for today's date, whilst still copying it to the same location with...
The command would be something like grep "$(date +'%d/%m/%Y')" server_log.txt where date +'%d/%m/%Y' generates todays date in the given format, i.e. 06/11/2020.
Cutting date from a file
1,396,027,959,000
Am using Iris Mini to filter the blue light at night, it works pretty well but having to execute it manually is annoying. So am trying to use cron to start it each night at 8PM. This is what i have written executing crontab -e. The command works if i execute it in the terminal Crontab 0 20 * * * sh /home/jogarcia/Soft...
The secret (as pointed out by @waltinator is to set DISPLAY correctly. That should probably be DISPLAY=:0 The format there is typically hostname:displaynumber, where hostname is optional. The second issue is display security. If you put the cronjob in your own crontab instead of root's, then xhost should not be needed...
How to create a night mode with cron
1,396,027,959,000
In /var/log/cron.log I noticed that CRON runs "@reboot jobs" right after I start my computer. Is there a way for me to see the list of the jobs CRON triggers then?
I don't think there's an easy way to see all configured cron jobs. First, check the global crontab file under /etc/crontab for anything containing @reboot. grep '^\s*@reboot' /etc/crontab As root, you can check the crontab of your users like this: crontab -u $user -l | grep '^\s*@reboot'
Can I see a list of jobs that cron runs @reboot?
1,396,027,959,000
I create a new user, john. Now I want to programmatically write a cronjob to the user john's crontab. #!/bin/bash #script name: cronbuild.sh cronjob1="0 */3 * * * /home/john/ad_dev/modem_dog.sh" { crontab -l -u john; echo "$cronjob1"; } | crontab -u john - Now this does indeed write to john's crontab. However, the s...
The message is from crontab -l -u john you used in the script. On one hand you did use the command. The only(?) reason to use it is to preserve the old crontab and append to it (not just overwrite it). This may be a good decision if there is an old crontab with arbitrary content you want to keep. This may be a bad dec...
Terminal returning: no crontab for user
1,396,027,959,000
My $EDITOR is vim and when launching vim the direct way, you can jump directly to what you are interested with the +/ option. For example: vi /var/spool/cron/crontabs/root +/rsync But using the actual recommended command crontab -e I don't see an obvious way to do that. Does anything exist?
I don't know what distribution you are using, but in Debian at least the source code just gets VISUAL or EDITOR, appends the filename and forks. So in that case no, you cannot pass additional parameters from the command line to your editor when using crontab -e. You could rebuild the VISUAL or EDITOR variables each ti...
crontab -e with jump to line option?
1,396,027,959,000
sid="GR1" if sapcontrol -prot PIPE -nr $sid -prot PIPE -function GetSystemInstanceList | grep 'GRAY' >> $LOGFILE then echo "STATE: SAP system is offline. (sapcontrol)" >> $LOGFILE echo "STATE: SAP system is offline. (sapcontrol)" else echo "ERROR: SAP system is still online. (SAP syst...
We face this kind of issue while using the packages is not from default RHEL. Cron may not run with the same environment as we run in the foreground. we may be required to give full path of commands. locate the path of sapcontrol by using the below command. whereis sapcontrol it may be /bin/sapcontrol or /usr/loca...
Crontab doesn't find a word
1,396,027,959,000
On Ubuntu I want to set up cron task to send email from my application. I think that I should run this crontab as user, not as root. Am I right? But I cannot go to the crontabs directory. I have permission denied. user1@srv:/var/spool/cron$ cd crontabs -bash: cd: crontabs: Permission denied user1@srv:/var/spool/cron$ ...
You didn't tell us the exact command you want to put in the crontab, so it's hard to tell definitely if it should be in the user's crontab. Permission denied is expected. Nothing to worry about. In general running crontab -e as unprivileged user is OK. The tool lets you edit a temporary copy and (after you save it wit...
Cron create crontab as user, not as root
1,396,027,959,000
I wrote a script that loops through every file in a folder and performs a simple operation on each file. That folder will almost always be empty and only occasionally contain a file, but I'd like the script to run automatically (and relatively promptly) when a file does appear. What's the best practice to do that? Rig...
incrond can run a command when a file appears. It uses inotify underneath. As has been pointed out in a comment, systemd can also monitor a directory and trigger actions. [Unit] Wants= my.service [Path] DirectoryNotEmpty= /path/to/monitored/directory
Cron loop best practices
1,396,027,959,000
==================================================== ==================================================== CHECK_BEGIN: DO_CRON ==================================================== ==================================================== [FILE]: CRON.ALLOW -rw-------. 1 root root 0 Sep 1 2017 /etc/cron.allow ============...
If the cron.allow file exists, it lists the users that may use cron. If it does not exist, the cron.deny file is checked. If the cron.deny file exists, it lists the users that may not use cron. This file is not consulted if the cron.allow file exists. If all users are denied the use of cron (as in your case, since th...
Interpreting cron output
1,396,027,959,000
I am writing a sed command that should uncomment an entry in crontab on sun Solaris 10. I have tried 2 ways and they are working on Ubuntu but they didn't work on Sun Solaris 10; it returns sed: illegal option -- E crontab: can't open your crontab file. crontab -l | sed -E '/#* *([^ ]+ *){5}[^ ]*run_all.sh/s/^#* *//...
You probably shouldn't overcomplicate the regex. To remove any possible hashtags at the beginning of lines containing the string run_all.sh, you could do: crontab -l | sed 's/^#*\(.*run_all\.sh\)/\1/' | crontab - Unfortunately, I don't have a Solaris system at hand to test it.
sed to remove leading comment on crontab with Sun Solaris 10
1,562,010,413,000
So this is a super weird issue. I have a python script that calls many bash commands via subprocess.call based on certain criteria. Now, the script runs just fine manually but when thrown into a cronjob it fails, BUT only when it gets to a certain part of the code. This part of the code runs a bstat and a bkill comman...
The subprocess call is looking for the bstat or bkill programs in the $PATH... except there is not $PATH` in the cron environment. Specify the full path to those programs, even inside the Python script, and it should work.
Python script runs manually but not in cronjob
1,562,010,413,000
I want to use the cron in the linux redhat 7 in order to run some jobs but I not want to use the crontab -e , since some users can change my conf so I did the following example cd /etc/cron.d vi test * * * * echo test >/tmp/test more test * * * * echo test >/tmp/test so I wait one min to see the log - /tmp/test ut...
Your crontab has only four time and date fields. You need five to be valid. If you are placing your script in /etc/cron.d you need to add the username that will execute the script as the first field following the standard time and date ones; like: * * * * * yael echo test > /tmp/test See man 5 crontab
create cron job in linux without crontab -e [closed]
1,562,010,413,000
I'm trying to work with crontab. In crontab -e: */10 * * * * rm home/user/Desktop/myFile trying to delete myFile at every 10th minute. I enabled Crontab using: /etc/init.d/cron start and then: sudo rcconf to ensure that the service remains after rebooting but it doesn't work! user@ubuntu:~$ sudo update-rc.d cron...
*/10 * * * * rm home/user/Desktop/myFile You forgot to add a slash at the beginning to make it an absolute path. As it is, it probably won't work. It should be: */10 * * * * rm /home/user/Desktop/myFile
Crontab configuration not working in Ubuntu [closed]
1,562,010,413,000
I try to clean the logs once a week with this cron command: @weekly find /var/log/ \( -iregex ".*\.[2-20]+" -o -iname "*.gz" \) -exec rm {} \; 2>&1 Is it good?
[2-20]+ is not the correct way to test if a number is in the range from 2 to 20. Square brackets in a regular expression just match a single character that matches any of the characters inside it. And - in the character set is used to specify a range of characters (e.g. 2-9 or a-z); the range 2-2 is the same as just 2...
Is my cron command good? [closed]
1,562,010,413,000
OS: Centos 7 | Shell: Bash | Virtual Machine: Virtualbox I have created a short script to check few servers on startup of my application and need to run this on every reboot. I have configured the crontab to run it every reboot however i am not seeing the output on the shell. @reboot /home/admin/scripts/connection.sh ...
A cronjob's output does not go to the shell. Most often, the output written to its standard output and standard error streams are collected and mailed to the owner of the cronjob. To log the output to a file: @reboot /home/admin/scripts/connection.sh >>/home/admin/connection.log 2>&1 This will make all output from th...
Output of cron on the ssh shell ?
1,562,010,413,000
I'm running this script in terminal and getting desired results, but when I set a cron to run it from /root/somefolder/ every 5 min, it does not do what its supposed to do. My root user crontab entry looks like this: */5 * * * * ~root/somedirectory/script.sh The script is: #!/bin/bash ## Variables ## host="`/bin/ho...
Try the following syntax for sendmail in your script: #!/bin/bash # some code /usr/sbin/sendmail -t <<EOF To: [email protected] "$address1" "$address2" Cc: [email protected] [email protected] [email protected] Subject: [Monitoring] $foo $bar at $host From: [email protected] Monitoring for example.com server loss of...
Script Runs Fine In Terminal, But Not Under Cron [duplicate]
1,562,010,413,000
I have configured crontab to have the following entry: */2 * * * * source /home/ubuntu/cronenv/python2.7/bin/activate && python /home/ubuntu/trial.py >> /var/log/mycron/trial.log 2>&1 && deactivate By tailing the /var/log/syslog file, I can verify that the cron runs every two minutes. This is the entry in /var/log/s...
It seems likely that source is failing, so && short circuits. Try redirecting stderr/out to a file from the first source and you should see the error. If trial.py ran at all, you should at least see trial.log created by the shell. The fact that it's not created suggests that this code was never run.
Crontab cron job not creating the redirected output file
1,562,010,413,000
I work in a Linux server which doesn't allow me to use cron. So, to bypass this, I write scripts that needs to run on a definitive time like this: while true do ... ... sleep 1d #changes upon requirement of my script done I always start the scripts in the background nohup ./script.sh &. My question is, sa...
Yes — you're consuming memory with those scripts. You've actually got two processes running, using memory: a shell (e.g., bash) sleep itself. sleep is going to be extremely lightweight, but the shell may consume a few megabytes of memory. On my system an idle non-interactive bash consumes ~1MiB and a sleep 0.7MiB. Y...
Unix Memory Question while sleep in background
1,562,010,413,000
I researched some examples and came up with two below that seem like they should work but only the first one executes: */5 * * * * /data/db/test1.py > /data/db/text.txt && hadoop fs -put -f /data/db/text.txt /tmp/ >/dev/null 2>&1 I have also tried */5 * * * * bash -c '/data/db/test1.py > /data/db/text.txt && hadoop ...
After investigating error in my mail, I did not have Kerberos ticket. The command line worked after Kerberos was resolved. I wrote a separate script that implemented Kerberos ticket and ran two commands mentioned in this issue. When I run the script from crontab, everything works fine
multiple cron jobs on one line (running consecutively
1,562,010,413,000
When working on an embedded environment (current one: Raspberry Pi with Debian Stretch) with an external RTC module (i.e. DS1307) I have to manually keep in sync both system and RTC clock. This can be achieved periodically calling hwclock -w - putting it in a cron job for example. I'm curious how the desktop systems h...
On embedded platforms like the Pi that do not come with a RTC the package adjtimex is not normally installed by default. This is the tool that manages the kernels RTC configuration, and defaults to configuring the kernel to keep the hw clock in sync with the system clock. Note that if you use hwclock or similar it wil...
RTC management in desktop and embedded environments
1,562,010,413,000
In the root users crontab on a Centos 7 server I have the following: 30 4 1-7 * * test $(date +\%u) -eq 7 && /usr/bin/needs-restarting -r || /usr/sbin/shutdown -r It should run every day at 4:30 between the 1st and 7th day of the month, then it tests if the day of the week is Sunday and only then execute the next com...
In a && b || c, command c is executed when either a or b exit with a value other than 0. Consequently, when test $(date +\%u) -eq 7 is false, your server reboots. According to its name /usr/bin/needs-restarting probably returns 0 when the server needs a reboot. Are you sure that this should not be a && b && c instead?...
Cron Job executing on the wrong day
1,562,010,413,000
Say I have 4 VPSs. In each one of these, the following cron commands run weekly, for local backups: 0 0 * * 6 zip -r /root/backups/dirs/html-$(date +\%F-\%T-).zip /var/www/html 1 0 * * 6 find /root/backups/dirs/* -mtime +30 -exec rm {} \; 0 0 * * 6 mysqldump -u root -pPASSWORD --all-databases > /root/backups/db/db-$(...
Assuming that each backup is a single file (by archiving both files above), SCP is going to be more efficient than rsync because it does less overall work other than transferring the file. As far as automation, you will need to set things up so that either: The fifth VPS can connect to the other 4 without needing a p...
Using rsync to backup 4 different VPSs to a fifth VPS that uses to store backups
1,562,010,413,000
On my Beaglebone Black device, I want to run python code at startup which is shared here https://github.com/acseckin/hmrid. The python code requires super user privileges. The Debian version I used on the device was installed with the image "Debian 8.7 2017-03-19 4GB SD IOT". The code works fine from the terminal. s...
Place the job in root's crontab with sudo crontab -e as @reboot /full/path/to/python /home/debian/hmrid/runhmrid.py Be aware that the job will be executed without your usual environment. This means that environment variables that may affect the way Python behaves may have to be set elsewhere for the script to work, ...
Crontab with sudo not working on Debian BeagleBone Black
1,562,010,413,000
In a minimal, non customized Ubuntu 16.04 server system, my /etc/crontab has the following code, which executes fine when executed manually: 0 8 * * * zip -r /UsualUser/backups/dirs/html-$(date +\%F-\%T-).zip /var/www/html 0 8 * * * find /UsualUser/backups/dirs/* -mtime +30 -exec rm {} \; # m h dom m dow # 0-59 | 0-23...
The /etc/crontab file on Ubuntu is the system crontab file. It should not be executable and its format is different from a user's crontab file. The difference in format is that its 6th field is the name of the user that the entry should be executed as. Also, % has a special meaning in crontab files. All % will be cha...
valid code in /etc/crontab won't be executed
1,562,010,413,000
I'm experiencing a small problem with a cronjob that runs a script of mine. The script looks something like this, it is named create_report.sh: #!/bin/bash cd /work/directory /some/command.sh > reports/report_$(date -d "1 day ago" +%Y%m%d).txt This is obviously a little simplified, but after writing the output to som...
When cron executes your cron job, it will (eventually) execute bash to run your script, but that bash instance will be non-interactive and not a login shell, so it will not source any of your profile files.1 If your /some/command.sh relies on any of those profiles (to set a variable or perform activity), then you need...
Cronjob overwrites Script Output redirect
1,562,010,413,000
I'm using for nicstat this command while true; do nicstat -eth1 1 60 > log-$(date +%F-%T).txt; done this command creates log file for each 60 seconds of my ethernet interface, the problem is the files are not for each clock minute, when running this command the first log file created can be some thing like log-12:00...
With zsh: #! /bin/zsh - zmodload zsh/datetime # for $EPOCHREALTIME/strftime... zmodload zsh/zselect # for sub-second sleeps zmodload zsh/mathfunc # for int() # wait till start of the next minute at first for ((next = (EPOCHSECONDS / 60 + 1) * 60;; next += 60)) { (( sleep = int((next - $EPOCHREALTIME) * 100) )) ...
make a loop run at the starting second of every minute
1,562,010,413,000
I have a security camera which sends pictures it captures to an ftp server on my network, and I developed a script to trim the old files from the receiving directory. The script works well when started from the command line, so I added a line to crontab to execute the script twice a day. # Remove old security images ...
It works from from an interactive session so i would surmise it's a setting in cron. Ensure you either don't have a PATH= line in your crontab, it if you do that it contains explicit directories (cron path assignment isn't additive like the shell) PATH=/home/myhomedir/bin:/usr/local/bin:/bin:/usr/bin
"du: command not found" - by CRON job
1,562,010,413,000
Can you please help me to create a script considering follwoing points. Step 1: First stop all existing cronjob (at 5 PM) which are running by using # Step 2: After that delete some files Step 3: Then again start all existing cronjob (by removing #) Thank you.
Julies simple solution, stopping and restarting the service as script (Debian Linux): #!/bin/sh service cron stop ... dowhatyouwant ... service cron start Or delete the crontab temporary: crontab -l > cronsafe crontab -r dowhatyouwant crontab cronsafe Approach for short interrupts; send a STOP signal to cron and res...
Script for modifying cronjob [closed]
1,562,010,413,000
Normally I don't post questions which are trying to get advice on how to directly a question in a textbook but in this case I feel it is necessary. The last questions said to write a C program and then set it up as a cron job. I've done that. The next question asks (so I assume it's possible): Explain how you can fi...
It sounds like it's asking for the time it took to execute your C program, not how long cron took to execute it. However, as others have commented, you can use the time program to time a command's execution, as below: $ time myprogram will give you the total time the program took to execute to completion.
Find time it took to run a cron job?
1,562,010,413,000
I am using a cron to execute a python script every 15 minutes during the day. At nighttime it should only run every hour. I made 2 entries for this: 0 23-5 * * * python /var/www/script.py > /dev/null 2>&1 */15 6-22 * * * python /var/www/script.py >/dev/null 2>&1 The one running during the day works fine. This is the ...
Change 23-5 to 23,0,1,2,3,4,5 or you can add two lines like so: 0 23 * * * python /var/www/script.py > /dev/null 2>&1 0 0-5 * * * python /var/www/script.py > /dev/null 2>&1 Or even as others have said (I forgot you can mix and match): 0 23,0-5 * * * python /var/www/script.py > /dev/null 2>&1 The reason why? Because ...
Cron stops working after a specific time
1,562,010,413,000
Admin note: This question is different then why is sudo path different then su because the environmental variables in a bash script ran from cron do not appear to carry over from environmental variables set for either users as sudo or as su. (See everything after the BUT.) When running sudo su and showing paths, I ha...
The environment in a cron job is, as you are seeing, different from that in a shell invoked by su - or sudo -s or sudo /path/to/executable. You can, however, set variables within the cron table: PATH="$PATH:/usr/local/bin" 0 0 * * * /path/to/run-me-at-midnight-with-path-changes.sh
Why are sudo su and bash root script paths different? [duplicate]
1,562,010,413,000
I have following case which may be is simple but I don't know which way is logically correct and how to do it exactly. I have multiple sites in /www/ each site is in own directory and user /www/site1/ // user site1 /www/site2/ // user site2 /www/site3/ // user site3 Now I want to make cronjob which will run PHP s...
Add a new user - let's call them allsites. Add the allsites user to the /etc/group for site1, site2 and site3 users. Run the script as the allsites user. Then run a single script with the different details per site included in the script. For (a very basic) example. A copy of script-name.sh is located in each of the ...
Cronjob(s) for multiple users
1,562,010,413,000
This should hopefully be a simple question, but I couldn't find the right search term in Google to show me what I was after... This morning I went to look at my crontab to remind myself of the location of a running script; crontab -e I found the location, and then exited Shift + Z + Z I was then shown a message [1]+ ...
That output is from the bash job control system. It is telling you that the first job ([1]) and the last process to be backgrounded (+) has been Stopped (aka paused/suspended). If you run the command jobs it will print currently backgrounded/suspended processes you will likely see your command listed. One way to stop ...
Info messages after editing crontab
1,562,010,413,000
I have postfix running in a Docker container. A cronjob try to send email, but reply “(CRON) info (No MTA installed, discarding output)” error in the syslog According to this link, the solution is to install postfix so CRON can send email. I have postfix running on this Host, is there a way to use it ? I have some o...
The problem is not that postfix is not running but that it should be listening on a mapped port 25 or 587 on the host. Even if that is the case, with not installing postfix on the host, there is probably no installed that sends the mail (gotten from stdin or commandline parameters) to the port. You install the clie...
Tell guest OS to use my dockerized mail server to send email
1,562,010,413,000
I'm busy setting up a back-up script to run on my Pi using rsync. I see that a number of people use the -v option in their cron jobs. Why? It's going to be run as root, and not in a terminal where someone will see it. I understand that maybe if something happens you can tail /var/logs/syslog, but the chance of that ha...
Usually, cron sends the output of the jobs it runs to the relevant user; so -v is useful there because you get an email with the full output of the rsync command. On a correctly-configured system, even mail to root goes to the appropriate user. For this to work you need mail to be setup appropriately on the system run...
Use of Verbose in a cron job
1,562,010,413,000
I have a script located at /home/user/backup.sh I'm trying to execute this script via my root crontab. It isn't running. The script works if I create the crontab under my user account. Is there anyway to run this script as the root crontab? Here is the line I am using. 25 20 * * * sh /home/user/backup.sh Contents of ...
root has full access on your system, but doesn't necessarily have all the keys to other systems that your normal user account has. So the trouble is: rsync -avz /home/user/backup user@myserver:/home/user/ ^^^^ If you cause root to execute this command as you, your keys will be used and th...
How to run a script outside of home directory via cron
1,562,010,413,000
I have some Java executable (jar) that is run my some shell script from a cron job once every night. That executable does not print log statements "as usual" just by printing them out in a sequential manner like line after line (print after print), but while it processes its data its printing a single line with status...
Trivially, assuming there are no vt100 escapes to handle, you might try pushing the output through sed 's/\r$//; s/.*\r//' or the awk equivalent awk '{ sub("\r$",""); sub(".*\r",""); print}' but this assumes your sed or awk can handle very long lines, as the carriage-returns obviously aren't newlines. Also, carriage...
how to properly log the output of a console program that frequently updates "parts" of the screen, resulting in a messy log file?
1,562,010,413,000
I have a cron-job, which is just a script, clearing directories, which accumulate files over time. Unfortunately, it is not firing. Any idea why. I have created the cron-job using cronmaker.com. How do I know it was not fired, because it is set to fire every night, yet there are old files in it. output of crontab -e ...
CronMaker uses Quartz cron triggers, which add a couple of non-standard fields (for seconds and years). You should drop the first and last fields for standard cron, use * instead of ?, and remove the leading . from your command: 0 3 1/1 * * /home/deploy/scripts/clearzip.sh will run every day at 3am. More idiomaticall...
Debian : Cron job not firing
1,455,896,903,000
I made a script called hello.sh and it contains the following: #!/bin/bash printf "$( arp-scan --interface=eth0 --localnet )\n" printf "test\n" after making it executable (chmod o+x) and running it (./hello.sh >> file.txt) I get the correct output in file.txt (which is the arp-scan result and the string "test"). But...
cron runs with a very minimal environment and a reduced path. It's always safest in scripts designed to be executed by cron to ensure all commands have the full path provided, or the script sets its own PATH variable. Try adding the full path to the arp-scan command.
Sudo cron job using arp-scan gives empty output
1,455,896,903,000
When I use time and date at the end of a crontab line like backup`date +%F_%T`.sql or like backup`date%d%m%y`.sql, my crontab command doesn't work. But when I remove it, it works perfectly. Why doesn't it work when I use time and date like date%d%m%y?
First of all you need to escape every % and you should also use a little different syntax with date. So e.g. this one will work just fine: `date "+\%d\%m\%y"`.sql
Why doesn't `date +%F_%T` work in crontab? [duplicate]
1,455,896,903,000
I have a cron job it's on runnable .jar but I really want to check the output logs in console. but I wondered also if this command below will start to run on 3:15am but this jar takes time a lot of time to comple, Is there possibility that the current running will be overriden to the next schedule? need some clarific...
The cron entry you specified will run at 3.15am (if the host is turned on) but there are a few things to check: The usercontext of the job: Can it find the java binary to start? Consider using the absolute path to java. Does the user have access to write to /var/log/wine.log? Output of stderr: Consider to log the er...
output logs in crontab does not work [closed]
1,455,896,903,000
I created a small bash script that takes a file using wget and then processes it using a php. The code goes like this: wget -U mozilla -P /home/logfetcher/ http://fakesite.com/log.`date -d 'yesterday' +%Y-%m-%d`.csv wait /usr/bin/php csv-editor.php /home/logfetcher/log.`date -d 'yesterday' +%Y-%m-%d`.csv /home/log...
What is cron log saying? Or syslog? If there is error with first part of command then second command (after &&) won't be executed. is script csv-editor.php in your PATH? If it isn't than you should run it with absolute path /x/y/my.script. I'm pretty sure that script isn't in your path, so "/usr/bin/php /x/y/script.ph...
Simple bash not running properly by cron
1,455,896,903,000
I was trying to create a cron job which runs a ruby code on digital ocean, however it seems I'm making a mistake. It doesn't give any error but it doesn't also do anything. I ran this cronjob on my raspberry pi however on digital ocean it doesn't work. Here my cronjob 59 17 * * * ruby /home/workspace/delta/analytics/a...
Different environment variables, working directory, ... You need to debug where exactly analyze.rb is bailing out. First, you're only redirecting stdout, not stderr. Errors probably go to the later, so adding a 2>&1 to the end may help a lot. Or setting EMAIL= at the top of your crontab to have them mailed to you. You...
Running a ruby cron job
1,455,896,903,000
I have set up a cronjob on my server which is supposed to run every minute and store the output in the given file. I have been trying a lot and saw a lot of links but nothing seems to work. Following is the line which I wrote in crontab -e * * * * * /root/snmp_codes/snmp/.\/snmpstats.py -f file -g > logfile.log Can an...
Fix the path so it's correct. Based on your comment it's likely to be /root/snmp_codes/snmp/snmpstats.py. You can also modify the command so that it captures stderr as well as stdout like this (the 2>&1 attaches stderr to stdout so you get both written to the logfile.log): * * * * * /root/snmp_codes/snmp/snmpstats.py ...
Crontab giving no result
1,455,896,903,000
So I have this in my crontab -e 0 0 * * * /opt/www/backup.sh And in the file, I have the following: #!/bin/bash FILENAME=$(date +%Y%m%d).tar.gz tar zcf backups/$FILENAME f The file is located at /opt/www But the backup doesn't get created at all. If I run backup.sh manually, then it'll run and create the backup of t...
The current (working) directory is probably not set to /opt/www when the cronjob is started. You can set it in your script backup.sh before the tar... line by: cd /opt/www or you can use the full path in the tar line by: tar zcf backups/$FILENAME /opt/www/f I can also advise to use a full path for backups/$FILENAME
Crontab to back up directory
1,455,896,903,000
Need to keep a track of the succeded jobs, on daily basis, with jobs ranging from /10 /20 minutes to twice/thrice a day, least for these every 10/20 minutes runs, I'd be interested to know if there are any ways to keep/maintain the counts for thsoe, maybe in the command part after the script's entry, but then how do w...
Few things: -add some kind of the timestamp to the job. -don't redirect anything to the /dev/null . -set a $MAILTO notification to send output to the required team We are using Nagios for this and also cronwatch
Is there any way to maintain counts in crontab?
1,455,896,903,000
I am scheduling the following shell script #!/bin/bash (echo open mailserver.nowhere.local 25; sleep 1; echo EHLO; echo quit)\ | telnet | grep "?Invalid command" if [ $? -eq 1 ]; then if [ -r /tmp/sendmail_stopped ]; then rm /tmp/sendmail_stopped /etc/init.d/sendmail start ...
Common mistake, wrong order of redirection, try this: … sendmail_alive.sh >/tmp/sendmail_alive.log 2>&1 It works like this: file descriptor stdout to /tmp/sendmail_alive.log file descriptor stderr to the value of stdout (/tmp/sendmail_alive.log) With your order, you first point the stderr where originally was stdo...
How do I suppress all email notification from cron for particular job?
1,455,896,903,000
I added this rule to the bottom of my crontab * * * * * /root/test.sh It basically resets iptables so I can fool around. If I mess up I won't be locked out of my box. When I run the script in bash writing /root/test.sh it clears everything as expected. However if I wait a minute it doesn't seem to execute. I ran the ...
You cannot run a scripts (as opposed to a binary) with SUID permission. Your script is executing, but as your user, not as root, so its iptables calls aren't working. Error messages from cron jobs go to local email. Make sure that local email is configured properly (some distributions don't do it by default). The easy...
crontab not executing my script?
1,455,896,903,000
I have a Python script that runs from the command line beautifully, but when I try and run it from CRON does strange things. The script generates, then runs an apk script file. The apk script file is saved in /usr/src/scripts/plots/core_temp_data/weeklyplots when run via the command line; but it is saved in /home/pi w...
By default, cron runs all jobs in the home directory of the user who owns the job. Make sure that your python script uses absolute paths when writing the output files, or it'll put them in the current user's home directory.
CRON path problems
1,455,896,903,000
Via my host I have SSH access and a control panel. I installed Rails via SSH on a light weight server. I want to reboot the server when it goes down. I think I need to start it manually since I want to start two servers which run on different versions of Ruby. I was wondering if I can use the "Cronjob" area on my con...
THe @reboot entry is started when cron is started, but that doesn't mean everything necessary to run your bundle application is up and running. Depending on the setup, e.g. your network might not be up at that time. I would do the following in your case: have the reboot job write a unique file in some known place ha...
How to create CronJob for running commands on reboot?
1,455,896,903,000
I run screen command through cron, where the codes is in lorem.sh files. This is cron codes: * * * * * cd /home/z; ./lorem.sh Inside lorem.sh: screen -S screenname -X stuff $'\033[B' sleep 1 && screen -S screenname -X stuff 2 sleep 1 && screen -S screenname -X stuff "lorem ipsum dolor" sleep 1 && screen -S screenname ...
Most versions of cron run commands using /bin/sh by default, and if the commands run any shell scripts (that don't have a #! line to force use of a specific shell), /bin/sh will be used to run them, too. On some systems, /bin/sh is dash, a shell that doesn't understand the ANSI-C quoting convention used by bash and ot...
Run screen command with variable & tick through cron (cron run .sh)
1,455,896,903,000
I've written a short script to copy Apache's server status to a log: #Save date and time to a variable dt=$(date) #Echo date and time to the log file as it's not included in server-status echo "Time :" $dt >> /var/logs/server-status.log #Grab machine readable server-status and add it to the log curl localhost/server...
The answer is: Yes, it can. Provided there is a bug in the script interpreter. But, in your code you are not doing anything funny so if you are using stable version of the shell, it's almost 100% sure your problem is somewhere else.
Can continually assigning a variable in a shell script cause a memory leak?
1,455,896,903,000
I installed an RPM on a CentOS machine that was supposed to merge its own files contained in a /etc/cron.d structure with the current /etc/cron.d. However it replaced the current contents. I believe cron.d is a symlink. How can I retrieve the original /etc/cron.d?
/etc/cron.d is not a symlink on my CentOS 5.x box: drwx------ 2 root root 4096 Feb 5 2013 /etc/cron.d So, if it's missing entirely, you can restore it with: # install -d -m 700 -o root -g root /etc/cron.d If something else is in its place, you could move it out of the way, recreate the directory, and then selecti...
How to rebuild /etc/cron.d on CentOS?
1,455,896,903,000
I am setting up my first cron on a Ubuntu Desktop system. I was curious to know if there is a way to lock a folder before a cron is ran and how to set it up? I am following this article. I am just trying to make sure I don't damage any files when moving them from and to the cron folder because it is on a shared net...
A simple script with locking and a delay before accessing files: #!/bin/sh if mkdir /tmp/myscript-running; then cd /mnt/share/whereever find . -type f -mmin +1 -print0 | xargs -i -n 1 -0 myscript.sh "{}" rmdir /tmp/myscript-running else : # previous instance still running, do nothing fi GNU find or e...
Lock folder when running cron
1,455,896,903,000
I have a Raspberry Pi which I want to use to automate downloads to a network drive. I would like to restart the machine on a regular basis using cron (I've heard they're not the most stable of things) but obviously, I would prefer not to restart it half way through an incomplete download. I'll probably be downloading...
Some dirty ideas : Poll running software using ps : if a wget instance is running, then do not reboot. Create a lock file when triggering a download, and poll the lock file Anyway, wget -c allow to continue an interrupted download.
How can I check if a file is being downloaded?
1,455,896,903,000
I am trying to issue the gnome-session-save --kill command via crontab. I used the command sudo crontab -e. In the file is this: PATH=/usr/bin 00 00 * * * gnome-session-save --kill The command does not run as it is supposed to. /var/log/syslog shows it running successfully however. In the command I've also tried the ...
Caleb was right about passing the correct display variable. I also used crontab -e instead of SUDOing it. In Ubuntu, all you would have to do is specify which display to pass in Crontab. So my command looks like this: 00 18 * * * env DISPLAY=:0 gnome-session-save --kill the env DISPLAY=:0 is what tells to pass the cr...
How to use gnome-session-save from cron?
1,455,896,903,000
I have a script thar I want to be executed each first minute of each hour. Thus, i made a second file named crontab.sh: $ cat crontab.sh #!/bin/bash #cript path script_path="/mnt/lap_c/home/ditsiaou/2024/climpact/stavros_keppas/weatherxm/beginning/basic_script.sh" # Add the cron job to run the script at the first min...
No, don't delete your crontab.sh file but if you want to remove the execution just remove the according line while using crontab -e it will edit the crontab using your preferred EDITOR. You can backup before your existing crontab using crontab -l > /tmp/file
Crontab run after deleting a file
1,455,896,903,000
I'm trying to create a single-line /etc/cron.d/ cron entry, which runs the same command serveral times, essentially to create multiple threads, for long-running jobs: * * * * * usertorunas "for i in {1..6} ; do curl -s 'https://www.example.com/path' &>/dev/null & ; done" What am I doing wrong here? It does not execu...
The outer double quotes should be removed, and it's an error to use both & and ; to terminate a statement - see for example Using bash "&" operator with ";" delineator? As well, cron runs jobs using /bin/sh by default which doesn't support brace expansion or the &> combined redirection - so either replace those with P...
Cron job with for loop, executing same command several times to create multiple threads
1,455,896,903,000
From the log it seems like it tries to run at scheduled time Apr 29 10:00:01 momspi CRON[13324]: pam_unix(cron:session): session opened for user admin(uid=1000) by (uid=0) Apr 29 10:00:01 momspi CRON[13325]: (admin) CMD (./media/backup.sh) Apr 29 10:00:01 momspi CRON[13324]: pam_unix(cron:session): session closed for ...
You are using ./media when I suspect you meant to use /media. If you use ./ that means you are giving a path relative to your current directory. So, for example, if you are in /some/dir/, then ./media would mean /some/dir/media. So give the full path to the script, presumably /media/backup.sh, instead and it should wo...
troubleshooting crontab not running
1,455,896,903,000
I've got a veeery simple script written in python that tests my internet connection na saves parsed data to a json file: #!/usr/bin/python3 import subprocess, json, os from datetime import datetime # run the bash script and parse results def speedtest(): result = subprocess.run(["/bin/speedtest-cli", "--simple"],...
A quick answer: Write a script in /etc/cron.hourly. runpy script: #!/bin/bash /bin/python3 /home/trendkiller/python/py_speedtest/main.py Then make it executable: sudo chmod +x /etc/cron.hourly/runpy Test with --report or --test: run-parts --report /etc/cron.hourly manpages.
Cron, python and saving to a file
1,455,896,903,000
So I'm seeing this weird thing (or at least, weird to me, with my tiny amount of experience). cronnext tells me the nextstring for an every-minute cronjob is the beginning of the current minute, ie in the past. eg, if I run cronnext at 02:11:27, it says: nextstring: Tue Jul 25 02:11:00 2023 ( rather than (as I'd naiv...
The tool doesn't exist on Debian so I downloaded the latest version, cronie-1.6.1 from its source repository on Github. The manpage writes in the DESCRIPTION, Determine the time cron will execute the next job. Without arguments, it prints that time considering all crontabs, in number of seconds since the Epoch, rou...
`cronnext` reports `nextstring` for every-minute cronjob as beginning of the *current* minute, ie in the *past*. Normal?
1,455,896,903,000
In Debian 12, the following command is run weekly: start-stop-daemon --start --pidfile /dev/null --startas /usr/bin/mandb --oknodo --chuid man -- --quiet which generates man caches in /var/cache/man But looking in that directory, I see all possible languages are being generated: ... ./zh_CN ./zh_CN/cat1 ./zh_CN/cat5 ...
mandb doesn’t generate all possible languages, it generates database caches for all installed manpages. Compare the contents of /usr/share/man and /var/cache/man: you’ll see that the languages in the latter correspond to the languages in the former. If you don’t need certain languages, you can remove the corresponding...
mandb generates all possible languages in /var/cache/man
1,455,896,903,000
What are the key differences between a Cron job and a scheduler, and in what use cases is using one of these tools more appropriate than using the other?
You have here a list of schedulers: https://en.m.wikipedia.org/wiki/List_of_job_scheduler_software Cron is one of them. A simple one. Some other may be more scalable or support dynamic programming of tasks, support dependancy, the presentation of a dashboard (which jobs was successful executed). There are plenty of ch...
Cron Job vs. Scheduler: Understanding the Differences and Use Cases
1,455,896,903,000
Below is my existing cron which i wish to enable crontab -l ####Cron to auto restart MYAPP ###*/15 * * * * ansible-playbook /web/playbooks/detectMYAPP/va_action.yml | tee -a /web/playbooks/detectMYAPP/cron.out I wish to enable cron by matching app name MYAPP I use the below sed command for the same: crontab -l> /we...
Using sed $ sed -Ei.bak '/#+(\*.*myapp)/Is//\1/' input_file ####Cron to auto restart MYAPP */15 * * * * ansible-playbook /web/playbooks/detectMYAPP/va_action.yml | tee -a /web/playbooks/detectMYAPP/cron.out -i.bak will create a backup file in case you need to roll back
Unable to uncomment just the cron by matching the string MYAPP
1,455,896,903,000
We have a crontab entry that ends up sending an ambiguous redirect error. Pretty sure it's the command to read the date, but don't know how to fix. Are there other solutions? /bin/sh redirects to /bin/bash /opt/startup-shutdown/startup.instances Other > /tmp/`date +%Y%m%d%H%M%S`-cron.log 2>&1 gives: /bin/sh: 1 : ...
crontab uses % for a special purpose: The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the crontab file. Percent-signs (%) in the command, unless escaped with backslash (), will be changed into newline char...
RHEL7 Cron entry gives ambiguous redirect error? [duplicate]
1,455,896,903,000
I'm trying to run a script that archives a dir every day at 10 PM but It is not executed nor logs send. Please advise .. [root@linux]# crontab -e 0 5 * * 1 /usr/sbin/aide --check 0 22 * * * /root/backup/script.sh >> /var/log/backup_crontab.log Script : [root@linux]# ls -lrt total 2 -rw-r-----. 1 root root 1002 Sep ...
your script isn't executable (-rw-r-----) where it should be -rwx-r-----). just do a chmod u+x script.sh to add root execution rights. except using sh /root/backup/script.sh running the script /root/backup/script.sh requires the script to be executable even from crontab.
crontab does not execute nor output send
1,664,887,245,000
I've got a python script that takes data from some XML files and displays them on a website. The script overwrites the index.html file each time it's run and replaces some text in a HTML template with data stored in some variables. The script works fine. I put the command in crontab to run every hour, and it works. Bu...
The location of the script is irrelevant to its execution. When cron runs a job it sets the current directory to the home directory of the user. You need to set the working directory yourself, or else modify your script to write to the correct place.
crontab -e is running my python script but its saving the results of the script in my home directory
1,664,887,245,000
This rtcwake job launched manually works fine : $ sudo rtcwake -m no -u -t $(date +%s -d 'tomorrow 07:30') but doesn't seem to run as a root cron job : $ sudo crontab -l 32 7 * * * rtcwake -m no -u -t $(date +%s -d 'tomorrow 07:30') If I log the command with $ sudo crontab -l 32 7 * * * rtcwake -m no -u -t $(date +%...
Two things about your cronjob: % should be escaped \% because that's special character for crontab and means a newline. always write commands with thier full/absolute path, since crontab doesn't read your shell's PATH variable.
rtcwake not executed as root cron job
1,664,887,245,000
The file: /etc/cron.daily/logrotate has the following statement: /usr/sbin/logrotate /etc/logrotate.conf The logrotate.conf file has the weekly directive defined inside. Now I have two rotational configuration files abc and def inside /etc/logrotate.d. abc has the daily directive inside it which to my knowledge will...
As I tried to explain in What should be the preferred approach while rotating logs - using the daily directive or putting the file path in cron.daily?, /etc/cron.daily/logrotate is irrelevant as far as rotation frequencies are concerned, unless you’re trying to rotate more often than daily. To determine what a given c...
Logrotate scenarios - Mix and match cron.daily and daily directive
1,664,887,245,000
I want to run a script on the 1st of every month. If the computer was powered off, I'd like to execute it the next time it turns on. Anacron fits in regard to the "powered off" use case but it only provides daily, weekly, monthly intervals. Monthly is too late and weekly way too early. I checked fcron but that package...
Something like this (untested) #!/bin/bash # run this via crontab on days 1-4 and @reboot # # Store the run_month here, or somewhere writable on disk not /tmp runfile="$HOME/run_month" # make sure $runfile exists, initalize to a non-month if 1st run ever [[ ! -f "$runfile" ]] && echo "init" >"$runfile" # # get the la...
Schedule a cron job on a computer that's not powered on continuously?
1,664,887,245,000
Suppose that we want to run a task every 20 minutes: 0/20 * * * * It would run at X:00, X:20, X:40 and so on. Every 15? 0/15 * * * * So it would run at X:00, X:15, X:30 and X:45. But what happens if we wanted to run every 45 minutes? 0/45 * * * * I am inclined to think that it would run at X:00, then at X:45, then ...
The value after the slash is the step value. (See the man page). So 0/45 in the minutes filed means it’ll run at 1:00, 1:45, 2:00, 2:45, 3:00, etc. it doesn’t mean every 45 minutes. /15, /20, /30, all work as expected because 60 divides evenly by those values. If you want to have it run every 45 minutes, you’ll like...
how does cron react to ranges where using a non-even separator?
1,664,887,245,000
I have a question. I have a project implemented on the brownie framework, the launch is only from the project folder, the script is called by the command brownie run /script/create.py -- network rinkyb. I want to create a task that will call brownie run /script/create.py -- network rinkyb in the crontab of the clloe a...
Did you try HOME=/home/denis/project/ * * * * * /home/.local/brownie run /scripts/create.py --network rinkyb ? As it stands, you're trying to run brownie using brownie itself. Furthermore, brownie isn't a shell and cron won't work with arbitrary executables in the SHELL variable.
How to create a crontab file for a program?
1,664,887,245,000
I set JAVA_HOME in .zshrc: export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre/ which is fine for interactive programs. But I have JVM programs running via cron, which uses Bourne shell. The bourne shell programs keep giving me this: groovy: JAVA_HOME is not defined correctly, can not execute: /usr/lib/jvm/default...
Assuming you are referring to your own user's crontab, to avoid duplicating the definition of JAVA_HOME you can export the variable in ~/.zshenv (instead of ~/.zshrc), which is read even in non-interactive, non-login shells, and run zsh -c 'sh /path/to/script' in your cron job (replacing sh, based on what the program ...
Sharing environment variables between zsh and bourne shell (for crontab)