Find the answer to your Linux question:
Results 1 to 4 of 4
- I' dlike to execute a python script at reboot on my pi. below are the steps i took but not happened: -sudo crontab -e -add atreboot python /home/Documents/pi/python/myscript.ps -save ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2014
    Posts
    13

    Question Crontab problem on raspberry pi


    - I' dlike to execute a python script at reboot on my pi.

    below are the steps i took but not happened:

    -sudo crontab -e
    -add atreboot python /home/Documents/pi/python/myscript.ps
    -save file
    -reboot
    -check with ps aux or top but cant see anything happening


    where can i check if the line is added to cron ?
    what can i do to fix this?

    * (at in atreboot is actually ampersand but i cant use it here)

  2. #2
    Linux Enthusiast
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    649
    Code:
    crontab -l
    is use to "list" your current contab.

    I assume that the entry looks like:
    Code:
    @reboot        python /home/Documents/pi/python/myscript.ps
    And not
    Code:
    atreboot        python /home/Documents/pi/python/myscript.ps
    Also cron uses these files (when they exist):
    /etc/cron.allow
    /etc/cron.deny
    And some distros require that the user (in your case root) be a member of the group cron and/or crontab as well.

  3. #3
    Just Joined!
    Join Date
    May 2014
    Posts
    13
    my script.py also writes data to a text file in the same directory as the script ,
    and its causing problems when i use crontab to launch it.

    How can i change the current working directory for the script to run
    at reboot by crontab service ?

    or is there some other solution?

  4. #4
    Linux Enthusiast
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    649
    1) Change the script to except the directory as an argument and have it CD into it.
    2) Change the command in the "crontab" so it changes directories by prepending in the command with "CD somepath && " (I have not tried this as I do option 1). Such as:
    Code:
    @reboot        cd /tmp && python /home/Documents/pi/python/myscript.ps

Posting Permissions

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