New answers tagged

1

If you have a script that runs properly when run from the command line in a shell but will not execute from cron, you might have a problem with the environment that cron is running in. Try appending: 2> /tmp/error.txt To the end of your statement that won't execute in cron to see what errors are happening during execution. Run the command with ...


0

A cleaner and portable solution would to check the timestamp of a file that you create by cron especially for this purpose. Create a cronjob that touches a file each minute readeable by the webbrowser, for example: * * * * * www-data touch /var/www/cron-testfile and check the timestamp with php: <?php if(time() - filemtime('/var/www/cron-testfile') ...


0

Two ways; first, some cron daemons allow environment variables to be set: PATH=blahdeblah * * * * * jobdejob Second, use the env(1) utility, which then runs the actual job: * * * * * env PATH=blahdeblah jobdejob Three! Use fully qualified paths in the cron jobs. No, no, four ways, as Jeff says, set the path in the script: #!/bin/sh PATH=blahdeblah ... ...


1

If you want to move it from daily to monthly run, you need to use mv and not cp as otherwise you would simply add a monthly run. sudo mv /etc/cron.daily/0yum-cron /etc/cron.monthly/0yum-cron should do what you're asking for.


2

The format seems to be correct (after correction applied posted in the comment above). Are there some special restrictions for having everything in a single line? In case you need to have everything in a single line, I would suggest to change the shell script to avoid Fridays 2-9am, eg #!/bin/bash # THIS CODE IS NOT TESTED # skip on fridays 2-9am # what ...


4

In general, rather than editing /etc/crontab directly, it's easier to use the crontab command. The syntax to change a non-root user's crontab varies slightly from platform to platform. For example on Red Hat Enterprise Linux, it would be: # crontab -e -u alex On AIX, HP-UX and Solaris: # crontab -e alex You may also need to add that user to cron.allow ...


1

Per terdon's request, I am posting this comment as an answer, so that the question can be marked as "answered" Instead of relying on script logging, especially if this will eventually be a cron job, consider sending output and error messages to one or more designated files(s) in your php code. When you run it in cron, it will create a session log ...


0

Depending on your system your environment variables may not be set. You can either call everything using their full path or add your environment variables by hand. To do this (per man 5 crontab) you can insert variables at the top of your crontab in the standard KEY = VALUE layout SHELL=/bin/sh ...


2

This was resolved in this bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1298192 Please make sure you have the latest kernel: 4.3.3-301


2

Here are a few tricks that can help you figure out what's going on: Get the offending process's PID: $ pgrep -a gzip 25267 gzip -c --best file On my system (where I've launched a big gzip job), that returns the single PID: 25267. You might have more than one so, make sure to choose the right one. The -a flag tells pgrep to print the full command line, ...


1

pstree provides a nicely formatted output displaying what spawned what (assuming the parent does not die immediately after spawning the gzip command) Also check out Is there an easy way to log all commands executed, including command line arguments?


24

Process tree While the process is running try to use ps with the f option to see the process hierarchy: ps axuf Then you should get a tree of processes, meaning you should see what the parent process of the gzip is. If gzip is a direct descendant of init then probably its parent has exited already, as it's very unlikely that init would create the gzip ...


1

1) The error pretty much speaks for itself: your script cannot find the mail binary. Either it isn't installed, or it is but isn't in your $PATH and therefore you have to call it specifying the full path (e.g. /usr/bin/mail). 2) You do not need to attach a timestamp manually to the payload passed to mail, as e-mail messages bear already a timestamp in ...


2

You will have to give absolute paths in your script, cron might run your script somewhere else, not in your $HOME. You probably haven't got the venerable mail(1) program installed. And if you have, for sanity's sake, also give full paths to any executables your script runs. In general, for any script that runs with extra privileges (as another user, ...


2

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 or by the shell specified in the ...


2

First, to debug and monitorize this, as a rule of thumb, add a MAILTO variable in the crontab, should a problem arises in the standard error, it emails you. # crontab -e MAILTO=mymail@mydomain.com 30 3 * * * /usr/local/bin/blahblah.sh Also notice if the command outputs something in the standard output you can redirect it to null if you don't want that in ...


0

I battled this issue for a few days, and found that to execute my root cron jobs, simply remove the username from the crontab. This seems like unexpected behavior. An upgrade broke the system, then after a clean install cron failed. Additionally to make it weirder, when I tried the suggested fix I kept getting bad magic number error :/ RESOLUTION: ...


5

How are you using cron -m? Are you passing it a script that sends mail to a group of people? If so, why not just put MAILTO=cron-people in your crontab, and define cron-people as a mail alias? Then you can just update that alias as necessary.


2

The moreutils package contains a program chronic for this purpose. You just call it like chronic my_program args ... Very handy in cron jobs.


0

Never trust cron env -version => source env setup before command. 0 0 * * 0 (. /usr/xx/myenv ; /some/cmd ) >> /usr/xx/mylog.log 2>&1 myenv include all setup what you need. PATH etc. Use export for variables.


0

I would recommend you do the following: Install some SELinux troubleshooting tools yum install setroubleshoot setools Scan the audit.log file and generate a report containing all discovered SELinux issues sealert -a /var/log/audit/audit.log Either address any issues or create a new policy to white list them using the commands provided at the end of ...


1

Use a sub-shell to limit scope: 0 0 * * 0 (export PATH=$PATH:/sbin; /etc/init.d/tic_minus restart)


0

First of all create a file to test Cron Job: $touch echo.sh Enter your script in the file and try it first manually once the script executing properly, you can schedule it for Cronjob. Set Permission: $ chmod +x /path/to/file/echo.sh Cron Job example: crontab -e * * * * * /path/to/file/echo.sh Save the Entry. You can also check the output ...


0

Are you sure it's not working? [nazu@palaceredirect ~]# crontab -l * * * * * /bin/echo hi >> /tmp/test [nazu@palaceredirect ~]# ls -l /tmp -rw-r--r--. 1 nazu nazu 6 Jan 17 20:54 test Check your account's mail to see if anything is reporting back. mail command. Restart crond if you're unsure. systemctl restart crond.service You might want to ...


1

It turned out that the issue lay with mailx's pager setting. It began using more for some reason, when previously it had used less (which does the escaping). Linking more to less again restored the old behavior.


0

If you have cron installed (which it normally is), you can make an entry in your crontab file that starts with @reboot (instead of the more usual minute/hour/day/month/day-of-week specification). That job will be run on bootup. You can find more information on this with man 5 crontab from the commandline.


0

You do not need to use cron because rsync can do backup when computer starts by running daemon. You should look at this forum post: Click here


1

You could pipe the output through tr before processing it further or sending it. ./your-script | tr "\r" "\n" | mail This should replace all carriage return characters with line feeds. The same would be possible within the crontab: * * * * 2 /path/to/your-script --args | tr "\r" "\n"


3

Just an add-on for Rahul Patil answer. Using his answer, I have achieved the required result the following way: * * * * * /path/of/myscript.sh * * * * * sleep 20s && /path/of/myscript.sh * * * * * sleep 40s && /path/of/myscript.sh This allowed me to execute the script 3 times per minute.


1

Quoting 'TNW' When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago. So to find a file that is only a day old, you can use either of the snippets below find /home/backups/* -mtime +0 or find . -mmin +$((60*24))


1

The main thing to realise is that anacron is designed to complement cron; you should really just configure jobs in /etc/cron.daily, /etc/cron.weekly or /etc/cron.monthly. anacron is not designed for jobs that run more frequently; its main purpose is to allow daily, weekly or monthly jobs to "catch up" on computers which aren't on all the time. anacron uses ...


0

In case you are using one or more SSD's, it may be beneficial to run the fstrim-all command regulary instead of using the discard mount option. When the discard mount option is used, a TRIM command is sent to the SSD each time a file is deleted. This command tells the SSD to really delete blocks that have been marked for deletion. Some have reported that ...


0

Tasks as: Backups Maintenance of log, cache, etc. Database maintenance Download of high volume data can be programmed trough cron to be executed on certain times when they don't disturb usual tasks of the server,



Top 50 recent answers are included