I wrote a bash script I saved it as a file getcalls.sh, I used chmod+x on the file to make it executable. It curls csv output from an api into a file in the same directory it runs in. It runs in a directory called data in one of my web folders. When I run it from command line it runs fine. When I try to put it in cron it doesn't run. My cron entry looks like this.
12 03 * * 3 cd /var/www/html/sitedir/data/getcalls.sh
Is the syntax incorrect?
Yes your syntax is incorrect. You must use it this way:
minute hour day-of-month month day-of-week command
But you provide cd command. Use it as follows:
12 03 * * 3 /var/www/html/sitedir/data/getcalls.sh
Related
Im trying to run PHP script on this location on every 15 minutes
0,5,10,15 * * * * /usr/local/bin/php /var/www/html/adform.php
and to put results of the script in specific folder in specific file and to compress it daily. Is it possible and how? Pls help.
This is possible.
Instead of running /usr/local/bin/php every 15 minutes, why not replace that call with a shell script which does everything you described?
This shell script would run your php script, pipe the output to a file somewhere on your system which you can then compress.
I'm having some problem with crontab.
I have this job:
27 09 * * * drush #ildeposito.prod status
I want to execute the cron job every day at 9:27.
But it doesn't work.
If I try to execute the command directly in prompt it works.
What's wrong on my crontab?
If I execute "date" from shell I obtain:
mar 3 set 2013, 12.55.13, CEST
If I put the output of date in a file, with a cron job, I obtain:
Tue Sep 3 12:55:01 CEST 2013
Another: this is NOT executed every minute on 13!
* 13 * * * date >>/tmp/temp_out_hour
This works:
*/15 * * * * drush #site.prod cache-warmer --timeout=6 --hub-pages-file=/home/sergej/websites/sute/site-cache.txt
http://www.site.org
The system seems to have problems with hours.
First things first, you need to specify what "it doesn't work" actually means. Do you mean you see no output? Get no mail sent to you with the output? Typically, standard output from cron jobs will be packaged up in an email and sent to the user running the job. If you want to see what the job is outputting, you can use something like:
27 9 * * * drush #ildeposito.prod status >/tmp/temp_out 2>&1
which will write standard output an error to that file (you also don't need the leading 0 in 09).
If a command works from a shell prompt and not from cron, it's usually a difference in your environment settings. You can test this by replacing your job with a very simple one:
27 9 * * * date >>/tmp/temp_out
and examining that file after it executes. If the date works but drush doesn't, your problem lies outside of cron itself.
cron starts processes with a minimal set of environment variables and you have to ensure you've configured a suitable set. See, for example, here:
We use /usr/bin/env to run drush so that we can set up some necessary environment variables that drush needs to execute. By default, cron will run each command with an empty PATH, which would not work well with drush.
When running drush in a terminal, the number of columns will be automatically deteremined by drush by way of the tput command, which queries the active terminal to determine what the width of the screen is. When running drush from cron, there will not be any terminal set, and the call to tput will produce an error message. Spurrious error messages are undesirable, as cron is often configured to send email whenever any output is produced, so it is important to make an effort to insure that successful runs of cron complete with no output.
In some cases, drush is smart enough to recognize that there is no terminal -- if the terminal value is empty or "dumb", for example. However, there are some "non-terminal" values that drush does not recognize, such as "unknown." If you manually set COLUMNS, then drush will repect your setting and will not attempt to call tput.
Other than that, there are numerous other problems that can plague cron:
having a command on the final line of the file with no newline at the end sometimes causes troubles.
having % in your command somewhere.
having had the cron daemon start with a different timezone setting.
That last one can sometimes be fixed just by restarting the daemon. Given your comments about the bizarre nature of the non-performance, I'd suggest that as a first step.
I have a cron job scheduled as below.what it will do is invoke RMAN in Oracle and then clear all the achivelogs in the oracle database which are 1 day old. But the issue is that it is not getting executed through the cron job. but if I execute the same script from the prompt it nicely delete the logs through RMAN. Please help me in sheduling this script...
05 07 * * * /x01/rman_backup/mahesh/logde.sh
contents of the script as follows
#!/bin/bash
/x01/oracle/app/oracle/product/11.2.0/db_1/bin/rman cmdfile=/x01/rman_backup/mahesh /logdelete.rcv
The Content of the logdelete.rcv is as below
connect target /
run
{
delete archivelog all completed before 'trunc(sysdate)';
crosscheck archivelog all;
}
exit;
Please someone help me in scheduling this. I'm using this in SUSE Linux version 11
Generally, use output redirection with your cronjob to collect errors in a file, e.g.
06 12 * * * /x01/rman_backup/mahesh/logde.sh > /x01/rman_backup/mahesh/output.txt 2>&1
Specifically, your problem is probably that logdelete.rcv will not be found from cron, as this job will execute in $HOME so the file would need to be there. If it's not, specify the full path to it.
You must have some initializations which are done for your console but not in cron execution. Initialize variables manually or manually source profile files in your cron line.
I am using ubuntu 12.04.I am using a script(./home/sam/code/imageUpdate) to synchronising images from server to a particular folder in local system. And I have to run the script in the evening always. So I want to write a crontab which will automatically runs the script.
My commands :
$crontab -e;
And added the scheduled time to the crontab file.
# 50 17 * * * cd /home/sam
# 52 17 * * * ./code/imageUpdate > image1.txt
Then I saved the file and waited for the result.
But I didn't get any result. No image was been synchronised to image1.txt file.
Have I left any step ?
Please help me out...
Thanks in advance.
Make sure you don't have hashes (comments) at the start of your crontab commands.
Additionally:
Crontab commands should be run in isolation.
Each crontab command will be run in its own context, changing directory in one instruction probably won't lead to that directory being sound for the next executed (they may be run in their own environments, e.g.).
To overcome this, write a simple shell script which encompasses all of your commands for a single action.
# MyCommand.sh
cd /home/sam
./code/imageUpdate > image1.txt
# crontab command
50 17 * * * /home/sam/MyCommand.sh
I've been trying to get my script to run each day at 06:01 AM.
The script fetches data and outputs it to an .xml file like the following.
#!/bin/sh
tv_grab_se_swedb --days 1 --quiet --output=/www/tv/tv.xml
Priviligies
-rwxrwxrwx 1 root root 68 Mar 4 10:31 fetchdata.sh*
Now when i run the script it works and I get my output in the .xml file and its a charm.
So i wanted to add this to crontab to run this script everyday..
Crontab entry
# m h dom mon dow command
0 6 * * * /www/tv/fetchdata.sh
But somehow the tv.xml is always empty after this script has been ran.
Any solution to this? Have i forgotten something?
-Anders
Check to make sure that tv_grab_se_swedb is in a location that is in the $PATH that cron uses.
Probably nine times out of ten, "unexplainable" errors in cron jobs boil down to path issues.
When you run fetchdata.sh from command line, $PATH variable differs from when thist script runs throught cron.
May be tv_grab_se_swedb can't be found in any of $PATH's and can't be executed
Simpliest solution: rewrite fetchdata.sh with fullpath to tv_grab_se_swedb (something like /usr/local/bin/tv_grab_se_swedb)