Shiva Krishna Bavandla
Shiva Krishna Bavandla

Reputation: 26688

How to schedule a bash file in cron jobs on linux

i am trying to schedule a bash script (cron.sh) in cron jobs below is my bash script code

cron.sh: (Please correct it if something wrong)

#!/bin/bash 
#chmod +x cron.sh

cd ~/main_file/folders/douys
python -u cron.py 

Please let me know how to make a bash file executable

Here cron.sh file runs some python file, and when i run the bash script (cron.sh) with the following command it works fine and python file is executing

sh cron.sh

But i want to schedule the above cron.sh file in crons jobs to run for every two mins

can anyone let me know how to do above

Upvotes: 1

Views: 1290

Answers (2)

m4573r
m4573r

Reputation: 990

You can schedule the job by running crontab -e and adding the following line in the end: */2 * * * * /path/to/cron.sh.

You should read man cron for more informations.

Upvotes: 1

mdm
mdm

Reputation: 3988

It's worth mentioning that, if your .sh is just a "wrapper" for the .py, you can add the following line to the beginning of you Python file:

#!/usr/bin/python

And then make it executable:

$> chmod a+x code.py

Then you can add directly your Python file as a cronjob following the instruction that m4573r explained. (of course, '~/cron.sh' becomes 'path/to/cron.py').

Upvotes: 2

Related Questions