|
|
-
hive query not running in cron job
Chunky Gupta 2012-11-22, 09:59
Hi, I have a python script :-
-------------------cron_script.py---------------------------
import os import sys from subprocess import call print 'starting' call(['hive', '-f', '/mnt/user/test_query'],stderr=open('/mnt/user/tmp/error','w'), stdout=open('/mnt/user/tmp/output','w'))
-------------------cron_script.py--------------------------- ------------------test_query---------------------------------
create table test (testcookie STRING, testdate STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
------------------test_query---------------------------------
under crontab -e, I have added this line:-
10 4 * * * sudo /mnt/user/cron_script.py > /mnt/user/tmp/log
..................... This cron job executes and "/mnt/user/tmp/log" file is created containing a string "starting". And "/mnt/user/tmp/error" , "/mnt/user/tmp/output" these 2 files are created but are empty. Also no table is created.
If I run this script normally without cron job, it is working fine.
Please help me in setting up this cron job.
Thanks, Chunky.
+
Chunky Gupta 2012-11-22, 09:59
-
Re: hive query not running in cron job
wd 2012-11-23, 05:54
Add the following line before your crontab config
source ~/.bashrc On Thu, Nov 22, 2012 at 5:59 PM, Chunky Gupta <[EMAIL PROTECTED]>wrote:
> Hi, > I have a python script :- > > -------------------cron_script.py--------------------------- > > import os > import sys > from subprocess import call > print 'starting' > call(['hive', '-f', > '/mnt/user/test_query'],stderr=open('/mnt/user/tmp/error','w'), > stdout=open('/mnt/user/tmp/output','w')) > > -------------------cron_script.py--------------------------- > ------------------test_query--------------------------------- > > create table test (testcookie STRING, testdate STRING) ROW FORMAT > DELIMITED FIELDS TERMINATED BY '\t'; > > ------------------test_query--------------------------------- > > under crontab -e, I have added this line:- > > 10 4 * * * sudo /mnt/user/cron_script.py > /mnt/user/tmp/log > > ..................... > This cron job executes and "/mnt/user/tmp/log" file is created containing > a string "starting". > And "/mnt/user/tmp/error" , "/mnt/user/tmp/output" these 2 files are > created but are empty. Also no table is created. > > If I run this script normally without cron job, it is working fine. > > Please help me in setting up this cron job. > > Thanks, > Chunky. >
-
Re: hive query not running in cron job
Chunky Gupta 2012-11-23, 10:18
Thanks, its working after adding this line :) Chunky.
On Fri, Nov 23, 2012 at 11:24 AM, wd <[EMAIL PROTECTED]> wrote:
> Add the following line before your crontab config > > source ~/.bashrc > > > > On Thu, Nov 22, 2012 at 5:59 PM, Chunky Gupta <[EMAIL PROTECTED]>wrote: > >> Hi, >> I have a python script :- >> >> -------------------cron_script.py--------------------------- >> >> import os >> import sys >> from subprocess import call >> print 'starting' >> call(['hive', '-f', >> '/mnt/user/test_query'],stderr=open('/mnt/user/tmp/error','w'), >> stdout=open('/mnt/user/tmp/output','w')) >> >> -------------------cron_script.py--------------------------- >> ------------------test_query--------------------------------- >> >> create table test (testcookie STRING, testdate STRING) ROW FORMAT >> DELIMITED FIELDS TERMINATED BY '\t'; >> >> ------------------test_query--------------------------------- >> >> under crontab -e, I have added this line:- >> >> 10 4 * * * sudo /mnt/user/cron_script.py > /mnt/user/tmp/log >> >> ..................... >> This cron job executes and "/mnt/user/tmp/log" file is created containing >> a string "starting". >> And "/mnt/user/tmp/error" , "/mnt/user/tmp/output" these 2 files are >> created but are empty. Also no table is created. >> >> If I run this script normally without cron job, it is working fine. >> >> Please help me in setting up this cron job. >> >> Thanks, >> Chunky. >> > >
+
Chunky Gupta 2012-11-23, 10:18
-
Re: hive query not running in cron job
wd 2012-11-24, 01:27
This problem was caused by some env values not include when run by crontab, it's a common error for shell script writing . :)
|
|