date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,585,076,958,000 |
I want to set up crontab every minute on Manjaro, so I've put some script every minute with:
$ crontab -e
* * * * * /path/to/my/script.sh
crontab: installing new crontab
Then I see it is installed
$ crontab -l
but I see it is not working, so I try to restart:
$ sudo systemctl restart crontab
Failed to restart cront... |
I've found a solution on Manjaro's polish forum. Instead of cron we should install cronie:
sudo pacman -S cronie
sudo systemctl enable cronie.service
sudo systemctl start cronie.service
Then we can configure like normal crontab.
| crontab.service file not found despite installed and configured crontab |
1,585,076,958,000 |
When I'm sending an email using mutt (output of a script from cron/cronie) I get the following lines at the beginning of my email:
To: [email protected]
Subject: Cron <root@alarm> /home/alarm/bin/script-name.sh
MIME-Version: 1.0
Content-Type: text/plain; charset=ANSI_X3.4-1968
Auto-Submitted: auto-generated
Precedence... |
In your cronie.service file put:
Environment="[email protected]"
where EMAIL is the email that you want your cron job (output only from cron scripts) to be emailed.
Change the line in cronie.service that has:
ExecStart=/usr/bin/crond -n -m 'msmtp -t' to:
ExecStart=/usr/bin/crond -n -m 'mutt -H - ${EMAIL}'
Where -H -... | mutt showing headers in email content when emailed from crontab output |
1,585,076,958,000 |
I have a cron that runs a script twice a week (Monday/Thursday) - this runs fine, but I need to stop it processing on the first Thursday of the month.
I'd like to adapt this code:
we=$(LC_TIME=C date +%A)
dm=$(date +%d)
if [ "$we" = "Thursday" ] && [ "$dm" -lt 8 ]
then
.....
fi
I would assume I just change the =... |
Using a bash test:
if [[ "$(LC_TIME=C date +%A)" == 'Thursday' && "$(date +%d)" -le 7 ]]; then
exit 1
fi
Note: Functionally this is no different than the test in your question.
Just add that to the top of your script. If it is the first thursday of the month the script will exit right away, otherwise it will run... | Bash condition that won't run on first Thursday of the month |
1,585,076,958,000 |
I'm trying to set up a cron job via cPanel on a machine running CloudLinux/CentOS.
The command should run a PHP script every minute to update stats;
cd /home/account/public_html/phpredmin/public/ && php index.php cron/index
This is running but not updating the stats. Instead, it outputs HTML. However, the same command... |
The problem was that CLI was using the correct version of PHP to run the script, but cron was using another (wrong) version. Not sure why that happens, but the solution was to run the command slightly differently to call the correct version of PHP;
cd /home/account/public_html/phpredmin/public/ && /opt/alt/php56/usr/b... | Command working in CLI but not in cron |
1,585,076,958,000 |
I'm running PHP 5.6 on an Debian 8 machine and hence there is a cronjob running as root for cleaning up session data:
09,39 * * * * root [ -x /usr/lib/php5/sessionclean ] && /usr/lib/php5/sessionclean
Did not even know I had this cronjob until last week when I started to get mails regarding this cronjob saying:
/bin/... |
Unless you're using the system-wide crontab /etc/crontab, there is no user field:
Sample user crontab file:
# Edit this file to introduce tasks to be run by cron.
...
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
As you can see the user field is missing.
The -x t... | cronjob [ -x /usr/lib/php5/sessionclean ] returns command not found |
1,585,076,958,000 |
A week ago I updated my wife's computer, and after a few days noticed that crond wasn't running. Running crond -d wasn't much useful, so I ran strace crond -d`. This error appears:
openat(AT_FDCWD, "/dev/null", O_RDWR) = 0
dup2(0, 0) = 0
dup2(0, 1) = 1
brk(NU... |
After some discussion on the ##slackware IRC channel about how this problem could occur, I noticed that there was a difference in the /etc/rc.d/rc.M file in my computer and the one at one of the participants.
Older versions of Slackware seem to manage the crond startup directly, while newer versions do this task indi... | crond won't start. Problem with temp directory /run/cron? |
1,585,076,958,000 |
My home server runs a couple of shell scripts regularly for maintenance tasks - mostly backup, but also other stuff. I would like to be alerted in case anything fails but also keep a log of when it works.
Currently my setup looks like this:
Cron calls one shell script which calls other scripts (just so the one won'... |
I have implemented the following:
Enabled output to stdout for various steps or added custom output, e.g.:
echo "Starting backup..."
rsync whatever && echo "Backup successful" || echo "Backup failed"
Checking the return codes of each step of the script, either exiting the sub-script immediately or continuing, retu... | How to monitor cron maintenance scripts? |
1,585,076,958,000 |
I am trying to use Shell_exec to a run a script which is dynamically created and stored in a php variable. Here is the script so far.
{ curl -fsS --retry 3 https://hc-ping.com/same-unique-id-here ; \
echo "name.of.php.file.here STARTED for id # $state_id" ; \
php "/path/to/my.file.php" -i 2 -h prod 2>&1 | tee -a /pat... |
I was hoping for more interaction on this question. I ended up using a variable to control what was executed. Here is the code.
{ unset -v failcode ; failcode="0" ; curl -fsS --retry 3 https://hc-ping.com/same-unique-value ; \
echo "\n$(TZ="America/New_York" date +"%m-%d-%Y %H:%M:%S %Z") my.process.name.php STARTED ... | Shell_exec of dynamically created script with else |
1,585,076,958,000 |
I want to play a video at a certain time. Like an alarm. for instance, at 07:00 play video.mp4
I have tried this with crontab and with at, but no success yet
|
I wrote a little script for that:
#!/bin/bash
[ "$1" = "-q" ] && shift && quiet=true || quiet=false
hms=(${1//:/ })
printf -v now '%(%s)T' -1
printf -v tzoff '%(%z)T\n' $now
tzoff=$((0${tzoff:0:1}(3600*${tzoff:1:2}+60*${tzoff:3:2})))
slp=$(((86400+(now-now%86400)+10#$hms*3600+10#${hms[1]}*60+${hms[2]}-tzoff-now)%86400... | Start playing a video at a certain time |
1,585,076,958,000 |
I have a cron job in machine 1 that opens/close machine 2 for a few hours.
Now i deleted all cron jobs in machine 1, so it wont open/close machine 2.
I have no crons,
To delete all crons in machine 1. I used:
sudo crontab -r
but for some reason the machine 2 continue to open/close
I even used to check cron log on ma... |
Well,
There was another service (third party) which i gave access key to my ec2 instance that open/shut my instance and i forgot about it.
Well, i deleted it back than and so i assumed it wont be active anymore.
Anyhow, the case is solved.
Thank you all.
| Cron on Amazon EC2 centos still executes even after delete [closed] |
1,496,407,618,000 |
Before, there was a
https://linuxmain.blogspot.de/2011/12/gathering-performance-data-with-sysstat.html
For SLES you can install the cron settings by
SLES10: /etc/init.d/sysstat start
SLES11: /etc/init.d/boot.sysstat start
SLES12: systemctl start sysstat
but on SLES12 it doesn't installs the cronjob for sar if we r... |
I believe systemd takes care of that by its own. So if you do systemctl enable sysstat && systemctl start sysstat as root, you should be set.
| How to put systat/sar in cron on SLES 12? |
1,496,407,618,000 |
qBittorrent-nox which was running perfectly until last week, but since then it always crashes on my Ubuntu 14.04. Theoretically it's logging, but the log file only conatines these lines:
******** Információ ********
A qBittorrent vezérléséhez, nyisd meg ezt a címet: localhost:8080
Web UI adminisztrátor felhasználó nev... |
How to test if a daemon is running? It depends. Some daemons has a file with the process ID in say /var/run/foo.pid. An example of that is /var/run/crond.pid.
$ cat /var/run/crond.pid
432
If the process is running it has a directory in /proc:
$ ls /proc/$(cat /var/run/crond.pid)
So if the directory in /proc does not... | How to write a crontab script, that will check a process' status and launch it if not running? |
1,496,407,618,000 |
I use Gmail and every so often I have to hack it back in that text/plain email should be rendered in a monospace font. This makes it much easier to skim system-generated reports, &c. The problems with this are that I have to re-hack Gmail every few years when they change their semantics, and I have more "developer" ty... |
Just found your question, hope the answer can be still relevant.
I am successfully running cron jobs with HTML output for years. It needs the following vars set in the crontab before your commands:
CONTENT_TYPE="text/html; charset=utf-8"
CONTENT_TRANSFER_ENCODING="8bit"
Note it is text/html but not multipart.
I haven... | Easy Way to Wrap CRON Output in HTML PRE? |
1,496,407,618,000 |
So I've noticed that I've dumped a lot of annoying comments in the top of quite a few crontab files by using
crontab -u user -l > /tmp/crontab.user
#muck with the file
crontab -u user /tmp/crontab.user
and now I'm stuck with
# DO NOT EDIT THIS FILE
and two other lines repeated over and over again in the top of my ... |
The cleanup script can look something like
sed -i '/^# DO NOT EDIT.*\|^# (.*/d' /tmp/crontab.user
because your version of cron at least puts # DO NOT EDIT and # ( in at the header part and you never use things that start like that in any of your managed code (and if anyone else does, they'll be sorry)
| How to update crontab for a user with a script without duplicating comments |
1,496,407,618,000 |
I have several Git repositories with LaTeX files that I want to have typeset automatically. The idea is to have a central bash script (run by a cronjob) that executes a bash script in every repository, which (1) pulls new commits and (2) executes make all, which should call latexmk on the changed LaTeX files.
The cent... |
The problem turned out to be that the path to pdflatex was being defined in my $HOME/.profile. I thus changed the cronjob to:
* * * * * . $HOME/.profile; bash .../cron.sh 2>&1 > .../cron.log
in accordance with https://unix.stackexchange.com/a/27291/37050.
| Latexmk, from Makefile, from bash script, from Cron - Latexmk not being executed |
1,496,407,618,000 |
I recently got a new DigitalOcean LEMP environment with Ubuntu. I tried making an SH script that uses CasperJS to scrape data from an external website to a JSON file, and a PHP script to parse the JSON and update a MySQL database. The SH is executed by a cron job. My crontab is as follows, meant to run every 90 minute... |
I ended up just running the commands in a single crontab line with && and inside of a bash -l -c statement, it is working now!
| CasperJS and PHP In Cron Job Cannot Open Files, Works Fine When Run Manualy |
1,496,407,618,000 |
I am trying to put these two Cron Jobs:
0 3 * * * ! sudo -u asterisk /var/lib/asterisk/bin/module_admin --repos extended,standard,unsupported upgradeall
30 3 * * * ! sudo -u asterisk /var/lib/asterisk/bin/module_admin reload
into a repository so that i can run a
wget www.website.com cronjob.(zip or text)
How wo... |
This is a HUGE security risk, but
wget www.website.com cronjob.txt
crontab -u username cronjob.txt
But your crontab looks wrong. Why do you need to sudo, cron jobs run as the user they are installed for. So you would be better to just put the lines in asterisk's crontab.
sudo crontab -u asterisk
then add
0 3 * * *... | Put two Cron jobs into crontab using wget |
1,496,407,618,000 |
For some testing, I need to reboot my system every minute. I have a busybox based system, installed cron using opkg. I setup a cron job using crontab, everything looks ok:
root@SL1000-1103DC:~# crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.1962 installed on Tue Jun 16 14:57:01 20... |
Sounds like cron was started before the time synchronization had settled, so the fix is to sync the time before cron starts.
| Cron not working at startup, but works if restarted? |
1,496,407,618,000 |
I have a crontab that creates a dump of my database every night:
20 3 * * * /path/to/dailydump.sh
dailydump.sh contains:
#!/bin/sh
DATENAME=`date +%Y%m%d`
BASENAME="/path/to/dumps/db_${DATENAME}.sql"
/usr/bin/mysqldump -hhost -uusername -ppassword databasename > ${BASENAME}
Permissions are:
-rwx---r-x 1 ... dail... |
To make sure the cron daemon is running and honouring the crontab, you could make a small test. Edit your crontab with an entry like this:
* * * * * /bin/date >>/tmp/test
After a minute check the file /tmp/test. If there is no file, the daemon is most probably not running. If that's the case I would get in contact wi... | Why does my cronjob not execute my shell-script? [closed] |
1,418,224,861,000 |
I am attempting to find the best way to determine when the second file (of a matching criteria) is created. The context is an audit log rotation.
Given a directory where audit logs are created every hour, I need to execute a parsing awk script upon the audit log that has been closed off. What I mean by that, is that ... |
For closure, this is the start of the script I am going to use. It needs more work to make it robust and do logging but you should get the general idea.
#!/bin/sh
# This script should be executed from a crontab that executes every 5 or 10 minutes
# the find below looks for all log files that do NOT have the sticky b... | How to determine the newly closed file within a continuous audit log rotation? |
1,418,224,861,000 |
I'm helping a friend with a server and it appears the server reboots every week on Sunday night. How can I figure out what is causing is the server to reboot? Aside from rebooting, the server appears to also be running maintenance scripts for their custom application. I am guessing there is something running both the ... |
This sounds like a crontab entry. I'd look through the /etc/cron.weekly directory and also through root's crontab entries crontab -l.
Additionally look through your /var/log/cron log file (on Fedora/CentOS/RHEL) or /var/log/syslog (on Debian/Ubuntu). There will be lines that look like this:
Aug 12 08:17:01 manny CRON... | How to figure out what is performing scheduled server reboots? |
1,418,224,861,000 |
I was given a task to create a cron which finds, kills and clears old puppet runs that were not successfully installed.
I am more or less looking for a starting point.
|
**THIS IS NOT PORTABLE TO SOLARIS**
In your cron job:
if [[ "$(uname)" = "Linux" ]];then killall --older-than 30m,1h puppet;fi
Do not attempt to run this or write this on Solaris systems. If you have Solaris systems in your infrastructure as a mixed Linux/Solaris environment, just walk away from this answer entirely.... | Creating Cron Task to kill stalled/failed runs in a system |
1,418,224,861,000 |
Hey guys, im trying to run a script using cron, im using a crontab created by the user ashtanga, in the crontab i have
*/5 * * * * /home/custom-django-projects/SiteMonitor/sender.py
in top of the script i have:
#!/usr/local/bin/python
and the user ashtanga does have executable permission to the file, but cron is no... |
The user does have permission as the permission is set to 755
The problem is that the user doesn't know of the environment variables needed.
Try using bash instead and see if it picks them up then. Otherwise, set them up manually
Start troubleshooting by running the script using the /bin/sh shell. You should get the s... | using cron to run script |
1,418,224,861,000 |
For some reason, my backup is not working, when it is started by cron.
Crontab entry
0 10 * * * /home/yzT/BackupDaily.sh
BackupDaily.sh
#!/bin/bash
/home/yzT/Tools/FreeFileSync/FreeFileSync /home/yzT/Tools/FreeFileSync/BackupDaily.ffs_batch
I can see cron starting my backup script in syslog.
Oct 20 10:00:01 debian C... |
If you are the only user on the system, you can just edit your crontab (with crontab -e) and add DISPLAY=:0.0 at the top of the file.
Alternatively, you can try running your backup job like so:
/home/yzT/Tools/FreeFileSync/FreeFileSync /home/yzT/Tools/FreeFileSync/BackupDaily.ffs_batch --display=:0.0
| My backup is not working when started by Cron |
1,418,224,861,000 |
I use Ubuntu 16.04 with Nginx and a few WordPress sites. Sometimes I don't visit a site for a long time (>=1 month) and it might be that the site is down.
I'm looking for a small utility that will email my Gmail account, if one of my Nginx-WordPress sites is down (without mentioning a reason).
Approaches considered so... |
Best bet is to use a service like uptime robot. Free tier will cover less than 50 sites, pro plan is quite cheap. It'll do a simple ping check or even HTTP status code check
The upshot of this is that you're not adding an additional point of failure (that you can control). You've no longer got to maintain and updat... | A utility to email myself if my site is down |
1,418,224,861,000 |
I try to write the message "Ran Cronjob XY" to a logfile if my cronjob ran.
Attempt:
/opt/cpanel/ea-php73/root/usr/bin/php /home/company/example.de/bin/magento list 2>&1 | grep -v "Ran Cronjob XY" >> /home/company/example.de/var/log/test.cron.log
But this fails and logs the output of the command /opt/cpanel/ea-php73/... |
if some_command >/dev/null 2>&1; then
echo ran successfully
else
echo failed
fi >>logfile
The above code will run the command some_command, discard its output, and then append the text ran successfully to the file logfile if the command finished successfully. If the command fails, it would append the text fa... | How to log certain message to a logfile when my cronjob ran? |
1,418,224,861,000 |
I currently have 50 cron scripting jobs created on crontab -e. These scripts check that various services are running. Sometimes when I'm testing the functionality of one service this requires me to remove a lot of cron jobs. This makes the bells and whistles shooting off constant alerts off an outage. My workaround cu... |
Save your crontab to a file:
crontab -l > my-crontab
Delete your crontab:
crontab -r
Then load back the crontab from the file:
crontab my-crontab
| Any way to quickly disable/renable cron jobs? |
1,418,224,861,000 |
Since I over-use my computer, I would like to block it for few hours, for example every day from 23 to 7, so that I cannot use it in that time frame.
Currently, I am using crontab to suspend/shutdown the computer when it comes the time, and I do that every minute, so that - in general - if I try to log-in or turn on t... |
Another approach is to disable the mouse and keyboard (assuming a system with USB input devices):
00 23 * * * rmmod usbhid
00 7 * * * modprobe usbhid
This won't prevent you from turning the system off and on again, which would re-enable the keyboard and mouse... You could play with blacklisting the module if you wan... | How do I "lock" my Linux box for few hours? |
1,418,224,861,000 |
I set up an anacron job:
1@hourly 0 name wget https://mydomain.com/actions/controller
So it runs hourly but I did not choose the time:
7:33 then 8:33 then 9:33 ...
Is it possible to define precisely the time to run as:
7:00 then 8:00 then 9:00 ...
Note: my hosting provider give me no choice between cron and anacr... |
No, anacron may not be used to schedule jobs for running at exact times like that. It is best used for making sure that, for example, maintenance script gets run at approximate frequencies, like daily, weekly, or monthly. It does not have a time resolution lower than one day.
Personally, I launch anacron from an @hou... | Is it possible to set one job to run at precise hour with anacron |
1,418,224,861,000 |
I have a web CMS that allows so-called action IDs, which are URLs. When these action IDs are accessed, they perform some action within the CMS.
I wanted to perform an action periodically and used cron for that purpose. Even though the cron always ran at the defined time, which I could track in the log, the action was ... |
Wrap the URL in single-quotes. What is happening is that the ampersand is getting interpreted by the shell.
curl 'http://172.16.0.47/index.php?ACT=47&id=6'
Without the quotes (assuming you are using a shell configured to not error out on unmatched globbing patterns), you would start the command
curl http://172.16.0.4... | URL gets truncated when accessing it using wget or curl |
1,418,224,861,000 |
I want to change my root password everyday based on the date. The password will be like a combination of a string and the date. The below code is working fine.
echo -e "pass"$(date +"%d%m%Y")"\n""pass"$(date +"%d%m%Y") | passwd root
But how to call it each time the system starts and at mid night when the date changes... |
I'm not sure why you would want to do that. If you're concerned about security, if someone discovers your password on 1 July, they'll know it on 31 July or 15 September...
To answer your question, if you want to ensure that the password update is done either at a scheduled time or when the system restarts, you want to... | Dynamic change of Linux root password everyday |
1,418,224,861,000 |
How do I instruct Ubuntu 13.10 server to:
zip svn repository
dump mysql database into .sql script
tar both files
copy backup tar onto sdb disk
Are there any premade tools for such kind of operations?
|
The short answer is yes, there are premade tools for each of those operations:
Use zip
Use mysqldump
Use tar
Use cp
zip is not so often used in my experience. You get better compression, and preservation of more of the Linux specific file metadata by making a .tar file and compressing that (e.g. with xz).
You shou... | Backup of svn repository and mysql database on daily basis |
1,418,224,861,000 |
root's default PATH is
$ sudo su
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
After creating /etc/cron.d/myjob
35 * * * * tim ( date && echo $PATH && date ) > /tmp/cron.log 2>&1
/tmp/cron.log shows the default value of PATH is:
/usr/bin:/bin
Is the default P... |
This depends on the version of cron you’re using. I seem to remember you use Debian; cron there sets a number of variables up as follows:
Several environment variables are set up automatically by the cron(8) daemon. SHELL is set to /bin/sh, and LOGNAME and HOME are set from the /etc/passwd line of the crontab’s owner... | Whose PATH value is the default PATH value in a crontab file? [duplicate] |
1,418,224,861,000 |
So we know that the fifth column in crontab means day of the week. But what day is considered as 1? What is considered the first day of the week? Is it Sunday or Monday?
|
Sunday is 0, Monday is 1, etc.
http://man7.org/linux/man-pages/man5/crontab.5.html
The time and date fields are:
field allowed values
----- --------------
...
day of week 0-7 (0 or 7 is Sunday, or use names)
| What is the first day of the week in crontab? |
1,418,224,861,000 |
I haven't been able to get crontab to execute any of my scripts on start-up. I want to know why it doesn't work. Below is an example of me trying to use it, and I've tried to provide as much troubleshooting information as I can.
$crontab -l
no crontab for server
$crontab -e
#I scroll down to the bottom of the file an... |
You have to use Ctrl+x to exit nano and install new crontab. Ctrl+z will just stop/send to background nano without installing new crontab. See attached screenshot:
| Using nano to edit a crontab [closed] |
1,418,224,861,000 |
Some colleauge suggested that I added a cron job for doing some things, but executing crontab -e and adding the following line:
0 1 * * * . /path/to/some/file.bash
To make sure this thing was working, I changed it to
0 1 * * * . /path/to/some/file.bash && date >> /some/log
so that I could check that /some/log has... |
Ok, first, there's two slightly different crontab formats. The one used for per-user crontabs, and another for the system crontabs (/etc/crontab and files in /etc/cron.d/).
Personal crontabs have five fields for the time and date, and the rest of the line for the command. System crontabs have five fields for the time ... | What does it mean to have 7 items in a crontab entry? |
1,418,224,861,000 |
I'm trying to use a cron job to see when the battery gets lower than a given threshold, and then to send a battery critical notification. However, when I make the cron job execute a script every minute, and make the script send me a notification, it doesn't work.
To make sure that it's not a permissions issue with the... |
I added this to my crontab and all my notifications work (currently tested with zenity and notify-send):
DISPLAY=":0.0"
XAUTHORITY="/home/me/.Xauthority"
XDG_RUNTIME_DIR="/run/user/1000"
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
| Unable to send notifications from cron job |
1,418,224,861,000 |
I want my crontab to be every 4 hours but from a certain time 1 pm:
I chose this config:
0 1/4 * * *
but if I save I get the error:
bad hour errors in crontab file, can't install.
This following works perfectly, but then I cannot decide the starting time.
0 */4 * * *
|
You can't have 1/4 as the hours. This means "run at 01:00 (1am), every 4 hours". What you need is "run from 01:00 (1am) until the end of the day, every 4 hours".
0 1-23/4 * * *
You could also write this with the explicit hour numbers listed out, but I personally find this harder to process visually, and it's not so o... | bad hour errors in crontab file, can't install |
1,515,732,416,000 |
Is it possible to print to crontab with an heredocument?
I tried these but failed:
cat <<-"CRONTAB" > crontab
0 0 * * * cat /dev/null > /var/mail/root
0 1 * * 0 certbot renew -q
CRONTAB
and:
bash <<-"CRONTAB" > crontab
0 0 * * * cat /dev/null > /var/mail/root
0 1 * * 0 certbot renew -q
CRONTAB
This o... |
As others have pointed out, crontab is a command, so all you need to do is feed it the heredoc:
crontab <<-"CRONTAB"
But as has been mentioned before, it’s an awful lot easier to manage cron jobs by manipulating files in /etc/cron.daily, /etc/cron.d etc.
| Redirect to crontab with an heredocument |
1,515,732,416,000 |
When I am trying to open crontab I see the next output:
ubuntu@macaroon:~$ crontab -l
crontabs/ubuntu/: fopen: Permission denied
When I add sudo it opens fine however, if the jobs don't work there:
ubuntu@macaroon:~$ sudo crontab -l
# Edit this file to introduce tasks to be run by cron.
# omitted such info
* * * * *... |
The crontab command has lost its permissions. For example, on my (Raspbian) system the permissions include setgid crontab (the s permission bit for the group):
-rwxr-sr-x 1 root crontab 30452 Feb 22 2021 /usr/bin/crontab
You can confirm this by running ls -l /usr/bin/crontab on your problematic system and adding the... | Crontab doesn't open for user |
1,515,732,416,000 |
I want the crontab for root to be agnostic, i.e. I don't want to literally specify in it that the admin user is jim. That is why in my crontab for root I introduced the variable au.
SHELL=/bin/bash
PATH=/usr/bin:/bin:/usr/sbin:/sbin
au=$(echo "$(head -n 1 /etc/doas.conf)"|sed 's/permit//;s/as//;s/root//;s/ //g')
5... |
The crontab format allows you to define environment variables but does not perform any substitution. In you example, the au variable is defined as the string $(echo "$(head -n 1 /etc/doas.conf)"|sed 's/permit//;s/as//;s/root//;s/ //g').
The simplest solution is to explicitly define the user in your crontab:
SHELL=/bin... | How do I declare and use a variable in crontab that will hold the name of the admin user account? |
1,515,732,416,000 |
I have a bash script that sources a file, which sources another:
script.sh:
cd /script/dir
source funcs.sh
funcs.sh:
...
source mode.sh
Now this script runs OK when I run it from command line, from within /script/dir.
But when I run it from crontab, the funcs.sh file can't find mode.sh.
Probably because for some re... |
Every process has a $PWD (working directory) cron does not run in your $HOME. Instead of cding in your script you can use this
#!/bin/bash
dir="$(dirname "$(readlink -f "$0")")"
echo $dir
$dir is the location directory of a script. For example
$ cd /
$ bash /home/junaga/script.sh
outputs /home/junaga because that i... | source doesn't recognize cwd? |
1,515,732,416,000 |
What would be the difference between the following two ways to run cron? Basically, I'm just trying to write to a file and seeing which one is preferred/correct:
2 * * * * python script.py >> /tmp/script.log
vs:
2 * * * * python script.py >> /tmp/script.log 2>&1
It seems they both write to a log but perhaps the firs... |
The first redirection appends the standard output (only) of script.py to the log file.
If the script produces any messages on the standard error channel (in Pythonese: writes to sys.stderr), those messages will be processed as usual by cron, i.e. the cron daemon will collect them and after the job has ended, will atte... | Difference between two cron redirections |
1,515,732,416,000 |
I'm using a cpanel where I've hosted an application. In my application I have to run some queries on minutes/hourly/daily basis. For that I'm using cron job from cpanel. Here is a cron command that I'm using:
* * * * * wget -O /dev/null https://******/sms_cron
The problem in this command is, it is sending an email wh... |
To stop wget outputting anything, redirect its output to /dev/null and ask it to be quiet.
* * * * * wget -O /dev/null --quiet 'URL'
This is equivalent to
* * * * * wget -O - --quiet 'URL' >/dev/null
It will still produce output for actual errors (which I presume that you want to see). To avoid these as well, add 2>... | Cron job creating new file |
1,515,732,416,000 |
If I run my backup script manually from the command line it works fine. No issue backup is created. In the crontab log, I can see the entry for running the backup at 2:00 AM, /home/sgaddis/copy-production-db.sh:
Dec 23 01:01:01 mapehr anacron[11921]: Anacron started on 2019-12-23
Dec 23 01:01:01 mapehr anacron[11921]:... |
From comments it is clear that you want to run the cron job as root.
You can schedule such a script in two ways:
Put it in the system's crontab in /etc/crontab. This crontab is a crontab file with an extra user field, like what you show in your question. I would not recommend this though as some Unix systems may ma... | Backup script is being executed in cron job but no backup is being produced |
1,515,732,416,000 |
On Ubuntu, what is the calling relation between cron and anacron?
I am confused by looking at /etc/anacrontab, /etc/cron.daily/0anacron and /etc/crontab.
From https://askubuntu.com/a/848638/1471
cron.daily runs anacron everyhour.
What does "cron.daily runs anacron everyhour" mean?
Is it "cron runs anacron daily vi... |
The anacron manpage describes what it’s supposed to do, and to some extent how it does it. You should trust that, and the contents of the files on your system, more than information you find on unrelated sites on the Internet (including this answer of course).
anacron’s job is to ensure that daily, weekly and monthly ... | Is it true that "cron.daily runs anacron everyhour"? |
1,515,732,416,000 |
I set the following line in cron job under /etc/cron.d/find_old_file
* * * * * root [[ -d /var/log/ambari-metrics-collector ]] && find /var/log/ambari-metrics-collector -type f -mtime +10 -regex '.*\.log.*[0-9]$' -printf '%TY %Tb %Td %TH:%TM %P\n' >> /var/log/find_old_file
this cron should find the logs that old... |
The % sign in crontab see man (5) crontab has special meaning (newline) and to get your command work you need to escape them.
A "%" character in the
command, unless escaped with a backslash (\), will be changed into
newline characters, and all data after the first % will be sent to
the command as standard inp... | cron job not redirect the output to file [duplicate] |
1,515,732,416,000 |
I have a Raspberry Pi 2, which I use as kiosk, for that I have installed Raspbian based FullPageOS distro.
Everything works fine, except some commands fail silently when trying to run from crontab.
I have 2 commands for switching kiosk on and off at certain times by the pi user:
$crontab -l -u pi
# m h dom mon dow ... |
The man page for the crontab file format (man 5 crontab) writes,
Names can also be used for the "month" and "day of week" fields. Use the first three letters of the particular day or month (case doesn't matter). Ranges or lists of names are not allowed.
Notice the last sentence: you cannot use mon-fri (but... | Crontab only runs some commands? |
1,515,732,416,000 |
Having read through the Wikipedia page on cron, it is unclear to me when cron begins to execute the tasks I have defined in the crontab file. Is it during the boot process - or even at the end of it - or later? I am sure that they are executed when I login into the system (Linux Mint 17.3), however what happens if I d... |
The tasks defined in the various crontab files are executed by crond, which is started during boot by your init (whether that's sysvinit, systemd or Upstart). crond processes tasks as soon as it starts, so you'll see crontab-defined tasks potentially start executing before the system has finished booting.
In any case ... | When do cron tasks begin to execute? |
1,515,732,416,000 |
I am testing out a Raspberry Pi with the aim to use it in a production system for logging manufacturing data. All is working well and I have been recording test data over the last month.
For redundancy and risk management I have a bunch of Python scripts that need to be scheduled.
In the past I have been working on ... |
Actually, cron is production-ready. It's been battle-tested so many times it's hard to accuse it of malfunctioning. What you might be experiencing is issues resulting from simple errors. It would help a lot if you specified what your problems with cron are, exactly.
As already pointed out by gaueth, you can append >> ... | cron - production-ready alternative |
1,515,732,416,000 |
I am getting a Bad Hour error for the following crontab entry:
*/05 17-05 * * * wget -q -O /dev/null "http://abcd/cron/abcd"
Is there any issue with this? I want the cron to run from evening 5 PM to morning 5 AM
|
As you are not specifying which system you are using, I am hoping your system use a "Vixie" or "Vixie"-related crontab utility.
Still:
17-05: is not considered a proper range (the lower limit being greater than the higher limit of the range).
You could instead write: "17-23,00-05"
From man 5 crontab:
Ranges of numb... | Getting a Bad Hour Error in crontab |
1,515,732,416,000 |
Mentioned in a comment in this post How are files under /etc/cron.d used?:
People might miss, that "the file names must conform to the filename requirements of run-parts" (see Debian's man cron). So filenames in /etc/cron.d/ which match the shell glob [!A-Za-z0-9_-] are ignored! Hence things like *.dpkg-dist or vi-ba... |
As explained in man 8 cron on Debian (the source of the quote):
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 (see the system-wide example in crontab(5)). The default system-wide crontab contains four ta... | Are directories such as /etc/cron.daily and similar restricted by naming rules? |
1,515,732,416,000 |
I need to schedule a script every two minutes from 10 PM to 5 AM next day from Monday to Friday, but I'm not exactly sure if the below is correct and will work, or if there's other correct answers...
*/2 22-00 * * 1-5 /myscript.sh
*/2 00-05 * * 2-6 /myscript.sh
Update: I expect to start it from Sunday night at 10 P... |
The first entry specifies a range that runs backwards. That should instead be
*/2 22-23 * * 1-5 /myscript.sh
This covers the range from 22:00 to 23:58, Monday through to Friday.
The second entry should probably not use zero-filled numbers:
*/2 0-4 * * 1-5 /myscript.sh
This covers the range 00:00 to 04:58.
The two ... | crontab entry for scheduling over night |
1,515,732,416,000 |
Here is my crontab entry which I basically want to run on April 1st of every year, but only if April 1st lands on a Thursday.
0 13 1 4 4 /path/to/my/script.sh
But this seems to be running every week. What am I missing?
|
problem of the crontab entry is already pointed out, but to execute your script as your expected date&time, change your job schedule to:
0 13 1 4 * [ "$(date +\%u)" -eq 4 ] && /path/to/my/script.sh
| Crontab not meeting all requirements |
1,515,732,416,000 |
I have a specific script that gets the IP address of a particular MAC. For this it uses arp, and it works correctly. The problem comes when I Program a crontab to run that script; it works fine and runs but the line where it runs the arp command does not work and, therefore the script does not finish correctly only if... |
The environment that cron is running your script in has a different value for the PATH variable compared to your ordinary interactive environment.
This means that your script does not know where the arp command is to be found, for example (as mentioned in comments).
I would suggest that you make a note in what directo... | arp doesn't run in script when run through crontab |
1,515,732,416,000 |
I have made (with a Stack Exchange help) a script that checks if the web application is available and restarts the web app daemon in order to get it running again (usually helps until I'm at work). It's supposed to run every hour.
I've added the following line to sudo crontab -e:
0 * * * * bash /usr/local/bin/test.sh
... |
crontab runs scripts in a different environment from login shell; in particular, PATH could be different or undefined.
Try to use absolute path on the commands (lynx, head ...)
You can get them with
which <command>
Moreover you should specify path for test.log.
| My script doesn't run according to cron schedule |
1,515,732,416,000 |
I have this cron in my crontab
00 01 * * * /srv/python/proj/acquisizione/acquisizioneAOK.sh >> /home/crontab_logs/acquisizioneAOK.out 2>&1; mailx -s "Cron output: acquisizioneAOK" [email protected] < /home/crontab_logs/acquisizioneAOK.out
which writes the stdoutput to a file .out and then sends me an e-mail with ... |
To overwrite the log file on each execution of the script, replace the >> operator with the > operator.
The >> operator appends the output to the file on each execution, and you would have a continuously growing file with that approach.
The > operator 'clobbers' the file on each execution, which results in any existin... | Overwrite file with stdoutput from cron execution |
1,515,732,416,000 |
production.log
[2019-02-11 10:18:18] GET /
[2019-02-11 11:18:19] POST blavadasdasdgd
...
... <--- A lot of in between logs and other data
...
[2019-02-12 11:18:20] INFO ::HTTPServer#start: pid=21378 port=4567
[12/Mar/2019:11:18:25 +0200] "GET / HTTP/1.1" 404 458 0.0086
[12/Mar/2019:11:18:26 EET] "GET / HTTP/1.1" 40... |
Make sure to append the output to the file, i.e. use >> and not >.
Next you can use "copy and truncate" to preserve the log:
cp production.log production.log.1 && cp /dev/null production.log
There is a small time window where the copy command is completed and the truncation of the logfile is performed so that you may... | Replace log file without affecting "Redirection of stdin and stdout" using nohup |
1,515,732,416,000 |
I have a configuration file that some of its lines is like below:
# Mandatory: no
# Range: 0-5
# Default:
DebugLevel=3
I want to change the 3 at DebugLevel to 5 at 2 AM then after for example 2 hours at 4 AM it change back to 3 again. how can I do this? with crontab or script?
|
You can use sed to change the value at given time with cron:
To change DebugLevel=3 to DebugLevel=5 at 2am every day and then change back DebugLevel=5 to DebugLevel=3 at 4am every day, add following lines to your cron with crontab -e
0 2 * * * sed -i 's/DebugLevel=3/DebugLevel=5/g' file.conf
0 4 * * * sed -i 's/DebugL... | change a value in a file |
1,515,732,416,000 |
I have this on my crontab
10 6 * * * java -jar /.../myproject.jar >> /../myjob.log 2>&1
I want run my app only the week (Monday to Friday)
This line is ok ? :
10 6 * * 1-5 java -jar /.../myproject.jar >> /../myjob.log 2>&1
|
That is a correct way to run the job on days 1 through 5 (Sunday being 0 (or 7)). Alternatively, you could explicitly list the days:
10 6 * * 1,2,3,4,5 java -jar /.../myproject.jar >> /../myjob.log 2>&1
You'll want to be careful about adding a "day of month" (field 3) restriction, apart from *; if both values are spe... | Schedule Cron only the week |
1,515,732,416,000 |
I'm trying to create basic script which will be run every minute from cron. Script script.sh is:
#!/bin/bash
DATE=`date +"%Y-%m-%d %H:%M:%S"`
IP=`ifconfig | grep "inet addr" | awk --field-separator ':' '{print $2}' | awk '{print $1}' | head -1`
echo "$DATE $IP" >> test.log
When I run this script by typing "./script.s... |
date is probably /bin/date and is in the default $PATH for cron jobs, which is not the same as the $PATH set on user login.
ifconfig is likely /sbin/ifconfig which is not in the $PATH.
Change ifconfig to an explicit full path (such as /sbin/ifconfig) to run ifconfig within a cron.
| problem with echo IP address |
1,515,732,416,000 |
I have the following set of commands:
docker exec -u www-data bin/console api:execute --object=Account;
docker exec -u www-data bin/console api:execute --object=AgreementType;
docker exec -u www-data bin/console api:execute --object=CFProgramLevel;
docker exec -u www-data bin/console api:execute --object=Product;
dock... |
Put the commands in a script and schedule the script with cron:
The script runstuff.sh:
#!/bin/sh
docker exec -u www-data bin/console api:execute --object=Account
docker exec -u www-data bin/console api:execute --object=AgreementType
docker exec -u www-data bin/console api:execute --object=CFProgramLevel
docker exec ... | How to run one job at a time but all of them each hour? |
1,515,732,416,000 |
Say I want to have a beep at 13:00. I would use
speaker-test -t sine -f 1300 | at 13:00
I can find that something is going to be executed with atq but how to get the precise scheduled command? (that is speaker-test -t sine -f 1300)
|
atq
will list the jobs:
4 Mon Apr 24 15:00:00 2017 a skitt
The first number is the job identifier, which you can then use with at -c to view the job’s contents:
at -c 4
Note that at jobs start with a lengthy setup to reproduce the environment in which the job was defined; you’ll see the command you gave at the en... | How to show a at scheduled command? [duplicate] |
1,515,732,416,000 |
For some reason, I cannot get a simple cron job working on my Mint 18 KDE system.
This is the job, it tells a script to run every minute. See the crontab line that I get when I type crontab -l:
# m h dom mon dow command
1 * * * * sh /home/martien/crontest.sh
This is the script crontest.sh:
#! /bin/bash... |
Your cron entry runs once an hour, at one minute past:
1 * * * * sh /home/martien/crontest.sh
If you want every minute you should use this:
* * * * * /home/martien/crontest.sh
Since you've declared your script to be a bash script and you've set it to be executable, just call it directly. Don't write a bash scrip... | Cron job not working Linux Mint 18 |
1,515,732,416,000 |
Is there a log of crontab for me to know if crontab is working fine? I am on Linux Mint 17.3.
What I have done:
ran crontab -e as root
it did not exist, so I chose nano editor and proceeded
entered this line 00 12 * * * /home/vlastimil/Development/bash/full-upgrade.sh
saved and exited
My goal is to automate updates ... |
Logs probably go to syslog, which varies depending on what syslog daemon is involved and how that is configured to log, start with
grep -r cron /etc/*syslog*
to find where and what is going on on the system, or per derobert under systemd the relevant command is
journalctl -b 0 _SYSTEMD_UNIT=cron.service
Adding a tes... | How do I know if crontab is working fine? |
1,515,732,416,000 |
I'm having some difficulties on understanding why the following cronjob does not work anymore:
30 3 * * * /path/to/backup_script.sh && tar -czvf /path/to/archived/backups/retain_last_3_backups/backup-community_$(date '+%Y%m%dT%H%M%S').tar.gz -C /path/to/source/backup/folder/ .
If I run it manually using the same user... |
The % symbols are special in a crontab entry, so you can't use them directly in your date format string.
man 5 crontab writes
The sixth field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh... | broken cron job after editing it |
1,515,732,416,000 |
I have a cron job for very 2 min and somebody told me that some servers do not allow 2 min cron jobs. basically from 30 min. it is true?
|
No, this is not true. The minimal step is one minute. But depend of service you want to run. Please share more details
| problem with cron job for every 2 minutes |
1,515,732,416,000 |
I was looking into how to programmatically add a cronjob, and came across this SO question which advises using the following one liner:
(crontab -l 2>/dev/null; echo "*/5 * * * * /path/to/job -with args") | crontab -
What does the trailing - mean when provided to crontab here?
There's nothing in the man pages of cro... |
From the manpage of crontab
SYNOPSIS
crontab [ -u user ] file
...
The first form of this command is used to install a new crontab from some named file or standard input if the pseudo-filename - is given.
So, the - instructs crontab to create the crontab entry from the output of the preceding command, which is piped ... | What is the meaning of a trailing hyphen in this crontab command? [duplicate] |
1,515,732,416,000 |
In Debian 10 (buster) I wan't to schedule a task with cron. This task is a python script who create a csv file. This python script start with:
import xmlrpc.client
import csv
When I execute it, without any cron task, I have this message:
/usr/bin/python /home/debian/api_odoo_contact.py
Traceback (most recent call la... |
xmlrpc.client is a Python 3 library (it was xmlrpclib in Python 2), so you need to specify a Python 3 interpreter:
/usr/bin/python3 /home/debian/api_odoo_contact.py
In Debian 10, /usr/bin/python is a Python 2 interpreter.
| Debian - Execute a python script with modules import |
1,515,732,416,000 |
I wan't to schedule a SQL query in a PostgreSQL database with a crontab.
In terminal, in root, when I run:
psql -U postgres -d my_database -h localhost -p 5432 -c "INSERT INTO schema.table (name) VALUES ('Insert with a command from terminal');"
It asking me a password. So I add it:
PGPASSWORD="mypassword" psql -U pos... |
Some implementations of cron (I think including the one that comes with Debian) lets you set the environment variables on previous lines:
PGPASSWORD="mypassword"
0 12 * * * psql -U postgres -d my_database -h localhost -p 5432 -c "INSERT INTO schema.table (name) VALUES ('Insert with a command from crontab and password... | Debian - Schedule a SQL query with crontab |
1,515,732,416,000 |
I try to name a file with rows count in a crontab :
* * * * * ~/script > "~/targetfile-$(rows-count).csv"
I can do :
* * * * * ~/script > "~/targetfile-$(~/script | wc -l).csv"
But I think I can do much better and not execute script twice.
Can you help me ? Thx
|
Write the output of your script to a temporary file, count the number of lines in that file and move the file to a new name:
t=$(mktemp) && len=$("$HOME/script" | tee -- "$t" | wc -l) && mv -- "$t" "$HOME/targetfile-$len.csv"
If you are not using GNU wc, you may get whitespace characters at the start or end of the va... | Redirect and rows count in filename |
1,607,029,596,000 |
I am using MX linux and i need next thing. I have a config for openvpn, it works perfectly both from manual launch via cli and from nm-openvpn application in my XFCE.
I want to launch my openvpn every morning at 9 am via cron, but with visual displaying in my XFCE like i launched it from GUI.
Which command does networ... |
There is no non-networkmanager command that is being launched when you activate the openvpn connection through NM. This is an internal procedure within NM that sets up the connection. To manipulate it through the command line you can use the nmcli command. Some kind of command like this should work:
nmcli connect up "... | launch nm-openvpn via cli |
1,607,029,596,000 |
I need to execute the following command every 15 minutes:
sudo chmod -R 777 /directory
I am using Ubuntu server. The instruction must execute with elevated privileges (root).
I was thinking of using the /etc/cron.xxx directory.
Can someone please direct me how to achieve this.
Thanks
|
If you want to execute a command as root every 15 minutes, add the command to root's own crontab:
sudo crontab -e
Then, in the crontab, add
*/15 * * * * chmod -R 777 /directory
Save and exit the editor.
Since cron jobs are running as the user who owns the job, root in this case, sudo will not be used in the crontab.... | crontab repeated schedule with elevated privileges |
1,607,029,596,000 |
Please find below script
if [ "$#" -eq 0 ]; then
dbs=('test_db_1' 'test_db_2')
path='/var/backups/'
else
dbs=( "$@" )
path='/app/mybackups/'
fi
dbuser='test_user_name'
dbpassword='test_pass_word'
now="$(date +'%d-%m-%Y_%T')"
currentDate="$(date)"
dayToSubtract=365
cd ${path}
echo "location: $path"
for eleme... |
I am leaving the old answer below, as it adds context and details. But I think your misunderstanding stems from what you assume sh yourscript ought to do.
What it does is to use sh (which differs by system, as you noticed ...) as the interpreter for the script name you pass.
What you seem to intend, though, was
sh -c ... | Bash script running perfectly fine on Centos 7 and giving exception on Ubuntu Bionic |
1,607,029,596,000 |
I comeback with a very strange behavior
when we run this command on Linux redhat machine
echo "$(tput bold)" start write to log "$(tput sgr0)" >> /tmp/log.txt
we get ended bold text in /tmp/log.txt
more /tmp/log.txt
start write to log <----- BOLD TEXT
but when we run it from cron job under /etc/cron.d
*/1 * * * ... |
tput bold writes the character sequence that is to be used to tell the current terminal it is running in to start writing in bold.
It knows the type of the terminal based on the value of the $TERM environment variable. That variable is set by terminal emulators or by getty.
tput queries the termcap or terminfo databas... | tput in a cron job does not output bolded text [duplicate] |
1,607,029,596,000 |
I want to learn how to use crontab. I see there are two manual pages:
crontab(1)
crontab(5)
Why are there 2 manual pages? What are the differences between them? Do I need to study both in order to use crontab, or is one authoritative?
|
crontab(1) is the man page of crontab command.
crontab(5) is the man page of crontab file.
The man pages are divided in sections as described in What do the numbers in a man page mean?. Each section groups similar man pages. For example, Section 1 holds user commands (commands runable by all users in the system). S... | crontab(1), crontab(5) what's the difference? [duplicate] |
1,607,029,596,000 |
I understand there is a lot of documentation on editing crontabs via script, and I can do this by adding an entry with the following command:
line="* * * * * /my/folder/script.sh"
( crontab -l ; echo "$line" ) | crontab -
However, myself and a few others each have our own "sections" in our crontab under a superuser. ... |
This inserts after all # SPECIAL_JOB lines the $line string.
crontab -l | sed '/# SPECIAL_JOB/a'"$line" | crontab -
| How to insert a line into a crontab AFTER a key word or string via script |
1,607,029,596,000 |
I'm having problem getting my crontab to work in my ubuntu server 18.04 running as a amazon ec2 instance.
I have the following line in my /etc/crontab file:
*/15 * * * * root /bin/bash /home/ubuntu/gzip/over_time_compile_ec2.sh
But it does not seem to work, and when running sudo service cron status i get the f... |
Having no MTA (like postfix or similar) installed will not make your cron job fail, but it prevents cron from being able to send the owner of the job any output of the job via email.
If your job failed (for any reason), or produced output, you would not get notified about it and that information would be discarded.
If... | Crontab problem in ubuntu 1804 |
1,607,029,596,000 |
According to this site I set up cron to execute a script for me, first just trying to get it to work with cat before doing the actual work I need to do (actual work will need root priviliges so I did everything as root to make my life easier later):
me> sudo su
root> crontab -e
Edited the file as follows, leaving a b... |
Your crontab is running at 1st minute of every hour. To run every minute you have to configure like this.
* * * * * cat /home/me/source.txt 1> /home/me/destination.txt
| cron doesn't execute scripts after setting it up |
1,607,029,596,000 |
I'm using HISTIGNORE to ignore the most used commands and HISTCONTROL=ignoreboth:erasedups to remove duplicates.
Is there a way to periodically sort the contents of the .bash_history in alphabetical order?
|
To see a sorted history without changing it, do:
history | sort -k2
To sort the history file, do:
sort -o ~/.bash_history ~/.bash_history
Then log out of bash by typing exit, and log back in. The new
terminal instance will have an alphabetically sorted history.
For the most cautious possible way to sort the histor... | Sort .bash_history content alphabetically |
1,607,029,596,000 |
I'd like to be able to add a log file that has a timestamp of the last time the cronjob was run. This is the current code i'm using
crontab -l > mycron
echo ""${var1}" "${var2}" "${var3}" "${var4}" "${var5}" tar -czf "$fsrc"/* > ./"$fdest"/"$fname"">> ~/cronlog.log 2>&1 >>mycron
crontab mycron
rm mycron
The log file ... |
With your echo line.
[zbrady@myserver ~]$ cat test1.sh
var1=0
var2=1
var3=2
var4=3
var5=4
fsrc=abc
fdest=def
fname=ghi
>mycron
echo ""${var1}" "${var2}" "${var3}" "${var4}" "${var5}" tar -czf "$fsrc"/* > ./"$fdest"/"$fname"">> ~/cronlog.log 2>&1 >>mycron
cat mycron
[zbrady@myserver ~]$ ./test1.sh
0 1 2 3 4 tar -czf ab... | Cron log file isn't updating |
1,607,029,596,000 |
Often times when there's an email address on a website, it is not just plaintext, but a link (hyperlink?). However, instead of containing an address such as https://unix.stackexchange.com it contains mailto:[email protected]
which - upon a click - opens a browser "page not found". This seems very useless, however a qu... |
They are a URI for an e-mail address that the browser can use to invoke an e-mail application in order to send e-mail to the given address. The browser should provide a configuration option to set the application used.
cron uses the unrelated MAILTO variable (i.e. MAILTO=...) in its configuration to know where to send... | What is the function of "mailto:[email protected]" |
1,607,029,596,000 |
I have read a number of posts on SE.com regarding cronjobs, crontab, and how to reschedule cron jobs. But it seems that, in my Debian environment, a session cleanup job schedule simply called "php", that is present in /etc/cron.d, specifying root as the user, and currently running every 30 minutes, cannot be reschedul... |
Welcome to Debian; you no longer use cron.
M. Kitt is right that Stack Exchange prefers one question per question, but in this case both questions stem from a fundamental mistake that you are making: You are erroneously assuming that you are running cron jobs.
As you can see in the very cron job description that is in... | cron reschedule seems not to be taken into account unless reboot occurs? |
1,607,029,596,000 |
I've installed Debian stable 9.3 server for an Nginx environment, and I consider upgrading it daily via cron:
0 0 * * * apt-get update -y && apt-get upgrade -y
My system is minimal and uncustomized: It's a VPS to run a webserver with only these ports open: 22, 80, 443, 9000.
My system has no third-party software (th... |
I think your premise is flawed — unattended-upgrades can be configured to apply any update, not just security updates. It also takes care of quite a bit more than just apt-get update && apt-get upgrade: it will avoid starting upgrades which require interaction (e.g. for configuration changes), it can be given a list o... | Upgrading Debian stable daily [closed] |
1,607,029,596,000 |
To edit the root crontab in Debian I do for example sudo crontab -e. To exit from the preferred text editor (Nano), I do CTLR+X.
So far so good, but what if I want that each time I exit crontab, a text will be echoed into the console (into "stdout").
The purpose is to echo a reminder message like:
If you haven't alre... |
You can assign the $EDITOR variable a script which first calls an editor and then produces the output:
#! /bin/bash
vim "$1"
echo "foo bar baz"
and use this call
EDITOR=/path/to/script.sh crontab -e
| Echo something to console each time you quit crontab |
1,607,029,596,000 |
I'm setting up a docker container which requires a cronjob to do a backup using awscli (authenticated via environment variables).
Since cron doesn't see my docker variables I'm printing them to a file and sourcing them before I run the aws command.
I have confirmed that the variables are set from cron yet awscli doesn... |
Environment variables can be set directly in the crontab(5); this will avoid the cost and complication of the additional shell execution and source steps. That is, your hello-cron file would instead contain something like
AWS_ACCESS_KEY_ID=(key removed)
AWS_SECRET_ACCESS_KEY=(secret removed)
AWS_DEFAULT_REGION=us-west... | awscli can't see environment variables but only from cron? |
1,607,029,596,000 |
This is my code in scriptrun (name of my shell script):
php -f a1.php; php -f b2.php; sh -e c3.txt
This is my cronjob command: /home/telia/www/robot/scriptrun, created as root
When I run script I get error message
Could not open input file: a1.php
Could not open input file: b2.php
scriptrun file is a... |
As was answered in a comment, the problem appears to be that your a1.php and b2.php scripts are not in your $HOME directory, which is where cron jobs will execute. Either add a cd /to/that/path command to your scriptrun script, or change the php commands to use the full path to those scripts.
| script in cronjob doesn't work with: "Could not open input file" |
1,607,029,596,000 |
I am getting an issue while running a cron job for exporting all databases on my Godaddy Shared hosting Cpanel account. But I have trouble finding the syntax error in below command.
Same command is working on my AWS Ec2.
mysql -N -ubackup -pt -e 'show databases' | while read dbname; do mysqldump -ubackup -p123 --comp... |
Crontab commands will have all unescaped occurrences of % replaced by newlines. This is from the crontab(5) manual on my system:
The command field (the rest of the line) is the command to be run. The
entire command portion of the line, up to a newline or % character, will
be executed by /bin/sh or by t... | What is causing my "Unexpected EOF Error while looking for ..." error? [duplicate] |
1,607,029,596,000 |
I'm currently on Linux Ubuntu 14.04 (I think).
So I previously had a cron.daily script which was working fine. I decided to use the same script but move it to cron.hourly and now it wont work.
/etc/cron.hourly/dstealth-watch-tv
#!/bin/bash
times=$(date)
echo "${times}:" >> /var/log/dstealth/watch-tv.log
/usr/bin/curl... |
Run this command to convert the file from Windows format to UNIX/Linux format.
dos2unix /etc/cron.hourly/dstealth-watch-tv
| cron.hourly "exited with return code 1" no output to log file |
1,607,029,596,000 |
I have created a bash script that runs automated EBS backups on AWS. It is kicked off via a cronjob:
0 2 * * * /bin/bash /root/backup_snapshots.sh > backup.log 2>&1
This works perfectly, but next thing I want to do is to add an exit code for whether or not the script runs successfully ( So I can configure a Nagios che... |
#!/bin/bash
exec 1>/var/log/backup/backup_sbapshots.log 2>&1
if /root/backup_snapshots.sh
then
echo "PASS"
else
echo "FAIL"
fi
Make your cron script as shown which will put the cronjob run status in the backup log file. Note that there's no mention anywhere of the $? variable as the if statement does it own it'... | Adding an exit code to log file |
1,607,029,596,000 |
I'm trying to make a Bash-script which checks if I've downloaded anything, and if I have it should scan that. I'm making it launch at startup using crontab, however that part doesn't work.
This is my code:
#!/bin/bash
inotifywait ~/Downloads -m -r -e modify -e moved_to --format '%w%f' | while read file
do
$(clams... |
The problem is with this line:
clamscan --bell --recursive --max-filesize=99999 --log log/myLogs.txt $file
This tries to write to log/myLogs.txt. If you are in your home directory /home/oneill, it will try to write to /home/oneill/log/myLogs.txt, which is probably the correct place. If you are in the root / directory... | Bash script not working in crontab |
1,607,029,596,000 |
From the PERIODIC(8) man page:
The periodic utility is intended to be called by cron(8) to execute shell
scripts located in the specified directory.
One or more of the following arguments must be specified:
daily Perform the standard daily periodic executable run. This usu-
ally occurs early in ... |
Your /etc/crontab file contains lines like this, by default:
# Perform daily/weekly/monthly maintenance.
1 3 * * * root periodic daily
15 4 * * 6 root periodic weekly
30 5 1 * * root periodic monthly
Obviously, 4:15 AM Sa... | If "the periodic utility is intended to be called by cron", why does the man page imply that periodic has its own timing? |
1,607,029,596,000 |
I have a cronjob I want to run every 17 minutes and it does, but it also runs on the hour. How do I keep it from running on the hour (example 13:00)?
CRON:
*/17 * * * * php script.php
CRON LOG:
Aug 10 16:17:01 CROND[1925]: CMD (php script.php)
Aug 10 16:34:01 CROND[1126]: CMD (php script.php)
Aug 10 16:51:02 CROND[11... |
You are asking it to run every multiple of 17 minutes, every hour, which is what it is doing (zero is a multiple of seventeen). If you want it to run only at :17, :34 and :51, try
17,34,51 * * * * php script.php
If you want it to run every seventeen minutes, you'll need to instead use * * * * * and add the time-c... | Cronjob Running on the Hour (not anticipated) |
1,607,029,596,000 |
I am on using CentOS 6.7 server and every few days my cron service dies.
I've tried checking: cat /var/log/messages | grep cron but there was nothing relevant.
How can I check what's killing the service?
|
So the issue turned out my own bug - I've made a process that goes up every 15 minutes. Unfortunately, the process when closed, would leave his child processes up and I've collected thousands of such processes every few days.
Every now and then CentOS would run out of memory and kill some process to get more memory. I... | CentOS - cron service dies every few days |
1,607,029,596,000 |
Currently I got stuck by trying to execute a shell script via crontab. It does not work and I can't figure out what is wrong here.
What I want to do is: Execute a javascript (index.js) file with nodejs periodically.
The file run-logger.sh is executable (-rwxr-xr-x) and located under /home/pi/apps/fritz-client.
run-log... |
The cronjob is running. The run-logger.sh script is being found and executed, or otherwise syslog would indicate that. But output from that is being sent to your mail inbox which is broken. Fix the MTA so it sends you mail (locally perhaps) so that you can see the output. Alternatively, modify your cronjob so that you... | Execute a shell script via crontab |
1,607,029,596,000 |
Below is a part of script which gives proper output when run manually
but gives incorrect output when run using cron:
sort < file1.out | uniq -ic |sort -nr> file2.out
When run on the command line, this gives a count where lines are
grouped ignoring case, such as:
73 /universal/webselfservice/pdf/r60.pdf
When running... |
The locale used under cron is different to that in your interactive environment. One has case case-insensitive collation, and the other does not.
This means that interactively, the first sort puts /universal/webselfservice/pdf/r60.pdf and /universal/webselfservice/pdf/R60.pdf adjacent, so uniq -i can combine them. B... | sort and uniq commands not running as expected when run though cron |
1,607,029,596,000 |
I have created an /etc/crontab file on a Mac OS X that runs a few simple commands. I would like to use the crontab to echo a statement in my terminal, logout from the OS (as if I was to point my mouse to the command Logout), and I am trying to test it by running an echo statement every two minutes. Here is what I have... |
If the actual intent is to force a logout of the active user of the system at 1300 every day, try this in the root user's crontab:
0 13 * * * osascript -e 'tell app "System Events" to log out'
If you don't wish to display a confirmation dialog to the user, you can use:
0 13 * * * osascript -e 'tell app "System Events... | Crontab on Mac OSX |
1,607,029,596,000 |
I'm trying to run rsync-books with a crontab. Typing crontab -e outputs:
55 12 * * * diegoaguilar /storage/bin/rsync-books
Where /storage/bin/rsync-books looks like this:
if [ -d "/media/Beagle/books" ]; then
rsync -rP --delete --verbose /storage/Copy/Books/ /media/Beagle/books >> ~/rsync-books.log
fi
Just to conf... |
Cron runs commands without an environment so there's no PATH variable set. Because of this you need to specify the full path to rsync in your script.
if [ -d "/media/Beagle/books" ]; then
/usr/bin/rsync -rP --delete --verbose /storage/Copy/Books/ /media/Beagle/books >> ~/rsync-books.log
fi
Also, if you're runnin... | Cronjob not being executed |
1,607,029,596,000 |
i have a cron in my crontab
45 18 * * * root /bkp_db.sh
but it is not working. it is not being executed. what im doing wrong?
Inside my script:
NOW=$(date +"%Y-%m-%d")
mysqldump -u root apps_db > bkp_apps/dump_app1_$NOW.sql
mysqldump -u root app_db2 > bkp_apps/dump_app2_$NOW.sql
zip -r bkp_apps/bkp_apps_$NOW.zip /var... |
Your personal crontab file should look like this
45 18 * * * /bkp_db.sh
There are several crontab files, each with a slightly different layout. personal crontab files, edited via crontab -e do not contain the username.
man crontab says,
There is one file for each user's crontab under the
/var/s... | cron not executing |
1,607,029,596,000 |
I got a cron format like this:
0 0 12 1/1 * ? *,
How to read it and what does it mean.
I understand things without slash but not this one.
|
Slashes means step values (has to be something that the maximum value of the element in question is divisible by) in which the execution will take place. First value is the range, so say 0-30, and the second value is the frequency, so for example 5. If the value was 0-30/5 in the minutes column, it would execute every... | cron job with slash |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.