Results 1 to 4 of 4

Thread: Something i don't quite understand.

  1. #1
    Join Date
    Apr 2008
    Location
    Belgium
    Beans
    174
    Distro
    Ubuntu Karmic Koala (testing)

    Something i don't quite understand.

    Hello reader, I have a question about the following situation:

    I have a perl script placed in the directory /usr/bin/, full path = /usr/bin/script10

    to envoke it in shell i type:

    Code:
    Nick@ubuntu:~$ script10
    to envoke it from python i use:

    Code:
    >>> import os
    >>> os.system(script10)
    My intend was to run a python script every minute in cron that countains the lines:

    Code:
    import os
    os.system(script10)
    this script worked perfectly from my terminal session, and ran without errors using cron, except for 1 thing, it did not execute "script10", after hours of debugging the script finding for other things that could have caused it to malfunction i came to the conclusion that i need to use the FULL path of the executable...

    my question is WHY do these things work normally in terminal sessions (where you can read the output nicely) and won't work when you use them with cron (making it harder to tell where it went wrong...)

    can someone give me the full history on this, because i feel i'm missing out on something here.
    Last edited by ethoxyethaan; July 1st, 2009 at 02:20 AM. Reason: fixed
    http://mm-rs.org
    Code:
    sudo apt-get install freedom

  2. #2
    Join Date
    Dec 2007
    Location
    United States
    Beans
    2,900
    Distro
    Ubuntu

    Re: Something i don't quite understand.

    When you are running a script, you have a path variable, you can see it with:

    Code:
    echo $PATH
    Root has no path (as a safety feature) and things run at the system level (such as the system crontab) have no path. With no path they only look in the current working directory for the referenced item. When developing scripts and other items for system maintenance or operation, you should use a full path.

  3. #3
    Join Date
    Jan 2007
    Location
    Michigan, USA
    Beans
    1,184
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Something i don't quite understand.

    so a crontab of
    1-59 * * * * /usr/bin/python script.py

    then inside of script.py
    import os
    os.system(/usr/bin/script10)

    that should work.

    probably dumb, but is that all the py script does? If so you should concider ditching it altogether, and just run the script10
    Last edited by t4thfavor; July 1st, 2009 at 04:42 AM.

  4. #4
    Join Date
    Apr 2008
    Location
    Belgium
    Beans
    174
    Distro
    Ubuntu Karmic Koala (testing)

    Re: Something i don't quite understand.

    No this is not all the python script does, thanks blueridgedog.
    http://mm-rs.org
    Code:
    sudo apt-get install freedom

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •