Search code examples
pythonpython-3.xhivecron-task

Is it possible to schedule CRON task for a python file using hive


I want to schedule a CRON job of a python file (ex: test.py) present at a server location (ex: X.X.X.X/home/myname/test.py). The CRON has to be set up using hive.

I did some research and found the below articles that came close to what I want to do. To schedule a hive query on Crontab

echo "Starting of Job"
hive -e 'select * from mytest.empl'
echo "Script ends here"

I want the hive query to be replaced by code which enable it to run the python file.


Solution

  • Hive is a framework for data warehousing on top of Hadoop and has nothing to do with cron scheduling. A cron schedule is a simple text file located under /var/spool/cron/crontabs on Linux systems. You can access it using the crontab command. For example, to open crontab file, you need to issue this command:

    crontab -e
    

    Each line in crontab is an entry with an expression and a command to run:

    You can add something like this to the crontab:

    * * * * * /path/to/your/python-job.py >> ~/python-job.log 2>&1
    

    This entry is added to run the mentioned python script (python-job.py) every single second.

    You can follow this link to see how to add jobs to cron under Linux or UNIX. Check out this link to quickly generate the cron schedule expressions.