Tag Info

New answers tagged

1

When PHP scripts work when run via Apache but not via cron, some common issues can be that the script uses variables only available during a web request such as $_SERVER variables (e.g. $_SERVER['DOCUMENT_ROOT'] or others) or $_GET variables, or it could be a different PHP is used for web requests vs. command line. Try running the script yourself in shell ...


1

You cannot get this information as crond does not provide it to the running job. For user cron jobs (and possibly others) you could define an environment variable in the crontab and have your job read it e.g. cron_scedule='* * * * *' * * * * * /home/test/test.sh cron_schedule='1-59 * * * *' 1-59 * * * * /home/test/test1-59.sh The environment variable ...


0

crontab -l gives you the current crontab for the user. You could easier cut out the values you need like this: crontab -l | grep -v "#" | cut -d " " -f 1,2,3,4,5


1

The answer that focusing on why it's crashing is the right thing to do. For future reference if someone is looking for a way to cron a check for an app running and start it if it's not, I've always done so with a bash script. For example: #!/bin/bash # Check if httpd is running if pgrep "httpd" > /dev/null then echo "Running" else ...


6

Redis shouldn't be crashing. I'd focus on that first. Is it running out of RAM? Use something like Supervisor or Monit, or run Redis through something like Upstart.


0

When this error occurs it is usually related to: Manifest not written correctly: Could be indentation problem. Could be a formatting issue, or the manifest file not starting with: class cron {} Puppet user has no permissions for your modules directory, default path is: /etc/puppet/modules But could also be ...


1

Remove the username from the cron line and it should start working.


12

Also, I want to be able to add/remove options when needed, but the rotation should stay intact. That's tricky. What does it mean for the rotation to stay intact after modification of the list of options? After all, you could be completely rebuilding the list, destroying any clue as to where you were. What you probably could do is set up a directory ...


1

As @Navern suggested, I put my whole command in to a bash script, then ran the bash script from cron. And, of course, an absolute path was necessary.


17

Let's say you want a different option for each day of the week. You can: Have a separate cron job for these: 0 1 * * 0 node ~/script.js option1 0 1 * * 1 node ~/script.js option2 0 1 * * 2 node ~/script.js option3 etc... Have bash provide the desired options for you: 0 1 * * * node ~/script.js case `date +%u` in 0 ) echo option1 ;; 1 ) echo option2 ;; ...


12

No, I can think of no clean way to do this. Just write a simple shell wrapper script that checks the date and starts up your node application with your required options each day.


3

Try adding cron.none to the line that logs to syslog *.*;auth,authpriv.none,cron.none -/var/log/syslog EDIT: more detail: From the ubuntu manpage for syslog http://manpages.ubuntu.com/manpages/hardy/man5/syslog.conf.5.html The special level ‘‘none’’ disables a particular facility. The *.* at the beginning says send everything to the designated ...


1

when you do ps aux | grep cron you are running two commands - ps aux and grep cron. ps aux lists all processes currently running, and grep cron matches any lines which contain "cron" in them. Obviously the crond process matches the word cron, but so does the grep cron process you just ran. It's matching itself recursively.


0

The best practice here is to write a script and call that script by full path within cron. This really is just reinforcing what Gene stated, but writing a script that will run those commands allows you the ability to test the script before placing it in a cron. Additionally, this makes cron easier to read over the long run.


1

Firstly, when configuring a crontab use the full path for any commands and scripts you are calling. For example: tee should be /usr/bin/tee mailx should be /bin/mailx date should be /bin/date Note: If the paths are different on your system change as appropriate Also, chaining commands in a crontab (i.e. piping, |) can get messy very quickly. It might ...


0

Cron doesn't allow % characters.


0

A home directory must be set for the user. If the user doesn't have one, you can specify it directly in the cron.d-file. You probably need to provide PATH=/usr/bin/ too, or specify full path for the command. HOME=/tmp 0 3 * * * apache /usr/bin/php /path/to/my/script.php


3

search no more, just type in shell man 5 crontab and read... hint: */5 8-19 * * * /path/script per @madhatter comment, you should add another job 0 20 * * * /path/script.


0

While cron could definitely get the job done, the canonical way to do this is to specify a user-data script that runs when the spot instance is launched. With the AWS CLI's request-spot-instance this is specified in JSON using the --launch-specification argument. http://docs.aws.amazon.com/cli/latest/reference/ec2/request-spot-instances.html This section ...


2

The most likely reason why commands would not be running when invoked from a crontab script is that they are not on the PATH environment variable. Crontab entries run with a minimal set of environment variables by default.


0

why don't you put this into userdata instead of cron? that's why they are made for: execute some code at startup. By using cron, you expose yourself to path issues that you would probably not have with userdata


1

You should really read the documentation, from man crontab(1) crontab - maintain crontab files for individual users The crontab -e command edits the current user's crontab(5) file which is found in (or created in) /var/spool/cron/crontabs/user. If you want to run a file daily, all you have to do is put it in the /etc/cron.daily directory and ensure ...


0

This will do the job: if [ $( date +%-d --date="tomorrow" ) -eq 1 ] then echo Last day of the current month else echo Not yet! exit 0 fi exit 1


4

You're using the syntax for an entry in /etc/crontab which has the user ID in the 6th column, but if you use crontab -e, you're editing the entry in /var/spool/crontab, which does not have this column since they are already separated per user. In other words, this is what you would put in /etc/crontab: 0 1 * * * root /sbin/shutdown -r now And this is ...


0

The best approach would be to rotate or move the log file BEFORE you process them. something like, #cp /path/to/log /path/to/moved_log/log.timestamp && echo > /path/to/log && grep ERROR /path/to/moved_log/log.timestamp Alternatively you can do not-so-preferred approach,count the number of lines in existing log file and process it. Store ...


1

The process takes a few hours. You probably want to ensure the max_execution_time is not defined in the php.ini or set sufficiently high and you might want to execute the script directly and not by a HTTP request to a web server. Will this lock up my server (haven't deployed it yet)? Possibly, but that completely depends on what the script is ...


0

Run crontab -e and add 0 1 * * * find . -name 'HERE IS NAME' | xargs rm This command runs in 1:00 AM.


3

It seems that you are running the same job as two different users. The log files should have been able to help you track that down. The timestamps on the dump files confirm multiple users.


0

Cron scripts run, by default, in a very minimal environment. The exact set of variables, and their values, should be described in crontab(5) (the details vary by OS).


-5

0 23 1-31/2 * * /path/to/your/script.sh Runs this script every 2 days i.e 1,3,5,7...31.


1

I guess you restarted rsyslog. As a result, you should then see your messages twice - once in /var/log/syslog and once in /var/log/cron. So what you are missing is that after logging to /var/log/cron, processing should stop. cron.* /var/log/cron & stop You can also configure filters to only log some messages somewhere else, or not at all - have a ...


1

In an shared hosting account or without access to the command line you can work with an secret parameter over http(s). I don't know if godaddy allow this, but you can try using wget or lynx in your cronjob call. Or use an independent cronjob service for that http-call. Create an longer string randomly, save it in your script and call the cronjob with this ...


3

There are several things you an do Use permissions to ensure that only the user who owns the cron job can execute the file e.g. 700 (rwx------) Have the script check to see if who it is being run by and continue appropriately (whoami) have mysql only allow the user who can run the cron job interact with the relevant database (grant permissions). Have the ...



Top 50 recent answers are included