Tag Info

New answers tagged

3

OK, so glenn jackman's answer works and it also answered my bonus question but I have since figured out another and what I believe to be more elegant way of making sure the cronjob runs in the directory in which the scripts are located. Simply by replacing */10 * * * * ~/mydirectory/myscript.sh with */10 * * * * cd ~/mydirectory && ...


0

Defining a PATH and MAILTO within the crontab should help.


1

myscript should have: cd "$(dirname "$0")" . ./myotherscript.sh When cron launches your script, the $PWD might be / so you should go to where your script is located if you want to use relative paths. You may find it useful to log your script's output: */10 * * * * ~/mydirectory/myscript.sh 2>&1 | /usr/bin/ts '[%FT%T]' >> ...


2

You are calling the script incorrectly. It should be: #! /bin/bash do-something do-something-else ./myotherscript.sh;


0

JosephR explained the logic better than I can. I suggest removing the cd /home/poppetapp && and just use the following to get your desired result. */5 * * * * pgrep -f test_java_10.jar || /home/poppetapp/test_java.sh > /home/poppetapp/test_java.out


0

I think this may be a grouping issue. I replaced your call to pgrep with a simple true or false: If the process isn't running, pgrep will fail: $ false || echo cd && echo run cd run If the process is running, pgrep will be successful: $ true || echo cd && echo run run In this case, you would want nothing at all to be executed! Running ...


0

The advantage of something like || is it allows you to run something based on a return code. E.g. if the left hand side is false then it evaluates the right hand side, but otherwise it doesn't bother. Here's the problem though - look at the man page for pgrep: The pgrep and pkill utilities return one of the following values upon exit: 0 One or more ...


0

It's seems to be a typo mistake. In the first script you use /var/log but in the new one it's /var/logs. Log is the standard directory but you seems to use logs


0

I need it to run every, say, 14 days. And at a specified hour (say, 4am). Is this possible with systemd? The easiest way to get approximately every 14 days is to make it twice a month. [Install] WantedBy=default.target [Unit] Description=Every fortnight. [Timer] OnCalendar=*-*-1,15 4:00:00 Unit=whatever.service That syntax is explained in man ...


0

I changed permissions to the script and the script: chmod u+x /path/to/script.sh and was able to execute the script. I'm not sure if it was necessary to change to root user, but I changed to root throughout the process


2

for cron you can to add a line to your crontab: MAILTO=archemar@mycompany.com maybe there is already a wrong MAILTO line in your crontab? But it might be better to find a universal solution, such as this: Add line(s) to /etc/aliases (one for each user for which you wish to substitute a destination email address): root: archemar@mycompany.com Rebuild ...


5

The cron job you pasted will run at 1am daily, and the > /dev/null 2>&1 part ensures that its output is thrown away. Remove this bit if you intend to receive the script's output by e-mail. There is a chance that your job is running, but simply failing early (perhaps because the environment provided by cron lacks things provided by your testing ...


-1

crontab -e, then add following item * * * * * a=`ps aux | grep abc.jar | grep -v grep | wc -l`; test $a -eq 0 && java -j /path/to/abc.jar


0

OP, at the top of my crontab, just before any jobs, I have these comments to remind me of the cron format, followed by the MAILTO variable setting. As good practice, all cron variables should be set before any cron job definitions. # min hrs dayofmonth month dayofweek command # dow = 0-6 where 0 is Sunday, 6=Saturday MAILTO=chuck So in my case, ...


1

it magically works again only thing i changed was 30 7 * * * /var/www/import/download_offers.sh > /var/logs/download_offers_cron.log ^^ here to 30 7 * * * /var/www/import/download_offers.sh > /var/log/download_offers_cron.log ...


2

From the cron man page: When executing commands, any output is mailed to the owner of the crontab (or to the user named in the MAILTO environment variable in the crontab, if such exists). The children copies of cron running these processes have their name coerced to uppercase, as will be seen in the syslog and ps output. So I would check your ...


0

Your crontab says to use bash, but when you run you script you actually shell out again to the 'sh' shell, thus you lose all your environment variables. I just had this problem last week. My problem was I had no path variable when the script ran in cron, but the script ran fine when I ran it manually. You can test this by doing this right at the top of ...


0

In this specific case, the file is located on /var/spool/cron/crontabs/flag03, and you can read it with the nebula account. But level03 doesn't have enough privileges to access it.


0

Check what your /var/log/syslog file says about cron job. Grep the word "cron" from the logs and check what is the error. Use below command to check the same. grep -i cron /var/log/syslog Otherwise everything you mentioned is good.


3

Can you clarify what you are asking ? But to have cron run at restart you could use @reboot. man 5 crontab These special time specification "nicknames" are supported, which replace the 5 initial time and date fields, and are prefixed by the ’@’ character: @reboot : Run once after reboot. @yearly : Run once a year, ie. ...


1

init.d, also known as SysV script, is meant to start and stop services during system initialization and shutdown. (/etc/init.d/ scripts are also run on systemd enabled systems for compatibility). The script is executed during the boot and shutdown (by default). The script should be an init.d script, not just a script . It should support start and stop and ...


1

chmod 0 /var/spool/cron/$username; touch /var/spool/cron/$username should do the trick. Restore with chmod 600 and touch (you need to change the file's mtime to make cron (attempt to) reload it). On at least Debian and probably with Vixie cron in general, chmod 400 /var/spool/cron/$username also does the trick, because that implementation insists on ...


0

Firstly, a clarification is in order: init.d is the directory that stores services control scripts, which control the starting and stopping of services such as httpd or cron rc.local is a service that allows running of arbitrary scripts as part of the system startup process In terms of whether its better to use rc.local or cron to run your script, I ...


0

After wasting some time I got it working. I just had to escape the character like this: $pass = '\)d@340kgfj';


1

Your cron seems not to know or use the &> shortings from bash. When you write the redirection like this /home/archiver/archiver.sh >/home/archiver/output 2>&1 it should work.I would prefer >>/home/archiver/output 2>&1 to always append to the logfile, too.


0

You can always use Cron job simulators to validate you Job run schedule. Link for one of the cron job simulator - http://www.dataphyx.com/cronsandbox/



Top 50 recent answers are included