0

I am using the FreeBSD variant as seen below:

[2.2.4-RELEASE][root@ROUTER.local]/home/Script_to_monitor_power: uname -a
FreeBSD ROUTER.local 10.1-RELEASE-p15 FreeBSD 10.1-RELEASE-p15 #0 c5ab052(releng/10.1)-dirty: Sat Jul 25 20:20:58 CDT 2015     root@pfs22-amd64-builder:/usr/obj.amd64/usr/pfSensesrc/src/sys/pfSense_SMP.10  amd64
[2.2.4-RELEASE][root@ROUTER.local]/home/Script_to_monitor_power:

I have written a python script that runs sucessfully using the below commnd in CLI:

 /usr/local/bin/python2.7 /home/Script_to_monitor_power/power_alarm_t2.py

The python script contains a shebang line as below:

#!/usr/bin/env python2.7

The location of python2.7 is as below:

[2.2.4-RELEASE][root@ROUTER.local]/home/Script_to_monitor_power: where python2.7
/usr/local/bin/python2.7
[2.2.4-RELEASE][root@ROUTER.local]/home/Script_to_monitor_power:

My objective is to run the above script as a cronjob. So i make my script executable using

[2.2.4-RELEASE][root@ROUTER.local]/home/Script_to_monitor_power: chmod +x power_alarm_t2.py

I have the edited the crontab as below:

[2.2.4-RELEASE][root@ROUTER.local]/home/Script_to_monitor_power: crontab -l
* * * * * /usr/local/bin/python2.7 /home/Script_to_monitor_power/power_alarm_t2.py
[2.2.4-RELEASE][root@ROUTER.local]/home/Script_to_monitor_power:

I also do:

[2.2.4-RELEASE][root@ROUTER.local]/home/Script_to_monitor_power: cron reload
cron: cron already running, pid: 43420
[2.2.4-RELEASE][root@ROUTER.local]/home/Script_to_monitor_power:

Now when i do:

[2.2.4-RELEASE][root@ROUTER.local]/home/Script_to_monitor_power:   ps -ef | grep cron
[2.2.4-RELEASE][root@ROUTER.local]/home/Script_to_monitor_power:

Q: My cronjob is not running after every 1 min. Please suggest what am i missing?

2
  • To run your script after every one minute, you need */1 * * * * /home/Script_to_monitor_power/power_alarm_t2.py.
    – slackmart
    May 10, 2017 at 5:18
  • 1
    @slackmart */1 * * * * is same as * * * * *, if i am not mistaken.Anyways, it still doesn't work
    – fsociety
    May 10, 2017 at 5:20

1 Answer 1

2

The line in your cron should be:

* * * * * /home/Script_to_monitor_power/power_alarm_t2.py

If you run python from nonstandard location maybe is wise to wrap this python script in shell script and add PATH and LD_LIBRARY_PATH.

You can also try to make shell script and add this script in cron to make execution of python with explicit point to python executable and add your home environment variables:

#!/bin/bash
source ~/.bash_profile
/path/to/python /home/Script_to_monitor_power/power_alarm_t2.py
3
  • 1
    tried, still doesn't work
    – fsociety
    May 10, 2017 at 5:26
  • Check my updated answer May 10, 2017 at 5:27
  • 1
    though i could not find the error as to why my python cron was not running directly, however i am now calling the python script using my shell script(which is running as a cron)
    – fsociety
    May 10, 2017 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.