How to make a python program start on boot? May need to use sudo.

741 views
Skip to first unread message

John Baker

unread,
Apr 8, 2016, 12:18:43 AM4/8/16
to BeagleBoard
My program runs fine but requires that I use putty.exe and type sudo python myprog.py to run it. I have been reading about systemctl and have written a service file and put it in /lib/systemd/system. It's called paint-flow.service, listing below. I have.. enabled it with systemctl enable paint-flow.service with no errors and tried systemctl start paint-flow.service with no errors but my program doesn't seem to start. When I check the status I get "code=exited, status = 203/EXEC" which doesn't tell me anything, at least nothing that I understand.

Also I tried the same thing with a one-line Hello.py program and same results.

Any help with this newbie problem, please?

[Unit]
Description=Paint flow control program

[Service]
WorkingDirectory=/home/debian/Desktop/
ExecStart=/home/debian/Desktop/python SimB.py
SyslogIdentifier=SimB
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.targetI am using Debian 3.8.13



John

Dennis Lee Bieber

unread,
Apr 8, 2016, 8:11:29 AM4/8/16
to beagl...@googlegroups.com
On Thu, 7 Apr 2016 21:18:43 -0700 (PDT), John Baker
<bakerengi...@gmail.com> declaimed the
following:

>ExecStart=/home/debian/Desktop/python SimB.py

The way I read that line says to run a Python interpreter located in
/home/debian/Desktop, passing it a file named SimB.py (located who knows
where).

I doubt you've installed a Python interpreter into your home directory.
I could see the line being:

ExecStart=python /home/debian/Desktop/SimB.py

to use the interpreter located on the regular search path (for something
starting as a service, likely the system Python).

Though one page found on Google mentions that systemd starts up with
fully "clean" environments -- so possibly not even the system search path
will be available and you need to provide both the path to the python
executable and the path to the script.

My other concern is: what do services use for stdout? Where would
anything from a print statement be sent? Maybe you need to provide output
redirection?
--
Wulfraed Dennis Lee Bieber AF6VN
wlf...@ix.netcom.com HTTP://wlfraed.home.netcom.com/

John Baker

unread,
Apr 9, 2016, 9:32:14 AM4/9/16
to beagl...@googlegroups.com, bakerengi...@gmail.com
You are right Dennis. Excellent suggestions. Now I can get systemd to
work and can run my simple Python program and write file to memory using
stdout.
Now to get my GUI program to run. I think I may have clobbered something
in the Debian or Tkinter or something since my GUI program is giving me
a Tkinter error, the same one I had a couple of weeks ago and got past.
But it's reared its ugly head again. Very annoying. I suspect I have to
reload the Tkinter.

Ugly error:
_tkinter.TclError: no display name and no $DISPLAY environment variable

Thanks very much,
John

Dennis Lee Bieber

unread,
Apr 9, 2016, 2:25:51 PM4/9/16
to beagl...@googlegroups.com
On Fri, 8 Apr 2016 21:11:22 -0700, John Baker
<john...@ieee.org> declaimed the following:

>You are right Dennis. Excellent suggestions. Now I can get systemd to
>work and can run my simple Python program and write file to memory using
>stdout.

Out of curiosity, which suggestion did it (incorrect Python invocation,
or stdout redirection), or were both required?

>Now to get my GUI program to run. I think I may have clobbered something
>in the Debian or Tkinter or something since my GUI program is giving me
>a Tkinter error, the same one I had a couple of weeks ago and got past.
>But it's reared its ugly head again. Very annoying. I suspect I have to
>reload the Tkinter.
>
>Ugly error:
>_tkinter.TclError: no display name and no $DISPLAY environment variable
>
Since Tkinter just invokes the external Tcl/Tk libraries, I'd interpret
the above to mean just what it says... Tk can't find an environment
variable providing the reference to the X-window display server. Did you
log-in through the windowing system?

If you're trying to run a GUI via systemd I don't think you'll have
much luck -- systemd (or other init process system) don't have
displays/consoles (which is why stdio likely had to be redirected; one is
probably supposed to be using the system logging functions for such).

I'll admit I'm very stale on Linux -- I'm still pondering what changes
occurred between the March 2015 image and the November 2015 image (I'm
still running Wheezy -- Jessie appears to have broken too much stuff, at
least with regards to books). I know I used to have a "task bar" at the
bottom of the screen with the former (along with the Beagle), but the
latter just has a context menu offering console terminal, web browser, and
switching desktop screens (and is otherwise completely blank/black -- if it
wasn't for the mouse pointer I'd have thought the display wasn't even
connected). I'm also not certain Cloud 9 is still functioning in the
November image.

John Baker

unread,
Apr 10, 2016, 3:51:59 PM4/10/16
to beagl...@googlegroups.com, bakerengi...@gmail.com
Dennis,
I did both since I realized you were right on both.

I had fixed the Tkinter problem a couple or three weeks ago and somehow
when I was trying to get systemd to work, I must have clobbered Tkinter
or something. So now I am reloading Debian Wheezy, bone50. I also was
having trouble with the latest Wheezy, 79. Don't know why. I was using
putty to start my GUI program with a keyboard and mouse connected to the
BBB thru a USB hub, per suggestion by Steve Plant on the BBB users
forum. I have myProg.py loaded at /home/debian/Desktop and found that I
had to start it with sudo python myProg.py. That has worked fine for a
couple of weeks or so and I was dismayed to see the Tkinter error show
up again. I have a 4D Systems 4DCAPE-70T attached to the BBB to give me
the GUI display and like I say, it was working terrifically for the past
two or three weeks.

Hopefully I will be able to get systemd to start my GUI program. I would
like it to start up upon resetting the BBB. Or maybe I can have a script
on the Debian desktop that I can get to trigger my GUI program? Somehow
I need to make it easy for the users to start the code, not requiring
the mouse and keyboard. Any suggestions?

I couldn't make any sense of the Debian bone79, just seeing the blank
screen like you said. Very strange, the bone79.
Thanks, John

Dennis Lee Bieber

unread,
Apr 10, 2016, 10:13:52 PM4/10/16
to beagl...@googlegroups.com
On Sat, 9 Apr 2016 21:12:00 -0700, John Baker
<john...@ieee.org> declaimed the following:

>Hopefully I will be able to get systemd to start my GUI program. I would
>like it to start up upon resetting the BBB. Or maybe I can have a script
>on the Debian desktop that I can get to trigger my GUI program? Somehow
>I need to make it easy for the users to start the code, not requiring
>the mouse and keyboard. Any suggestions?
>
I'm not accustomed to systems that "start" in a user account (at least,
not since my TRS-80 and Amiga days -- even W95 required a login, although
it was a blank password, as I recall).

Possibly something in the account .profile can determine if an X-window
environment is available and start your program as a background task?

I don't know under what conditions the X-window environment is
started... Does it detect HDMI/LCD connection, or does it always create an
auto-login X-window session regardless...

William Hermans

unread,
Apr 10, 2016, 11:21:52 PM4/10/16
to beagl...@googlegroups.com
W95 required a login, although
it was a blank password, as I recall).

Getting way off topic here but . . . Windows 95 had zero passwd protection. You could set a passwd, but it would not do anything . . . so a person could enter a blank passwd at the screen saver, and just log back in - heh.

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

evilwulfie

unread,
Apr 10, 2016, 11:25:54 PM4/10/16
to beagl...@googlegroups.com

A cron job maybe?

john....@jlmei.com

unread,
Apr 14, 2016, 3:48:58 PM4/14/16
to BeagleBoard
I was also looking to run my python script on boot so I did a couple things that worked as a a short term solution. I added 2 lines to my crontab, an @reboot line to run the program when the device starts up as well as a bash script to ensure the program is still running.

(Replace main.py with your program name and make sure it doesn't match anything else that may be running)

crontab -e

# Runs when the system boots:
@reboot sudo python /path/to/program.py

# Runs every minute and checks that your program is running:
* * * * * sudo bash /path/to/check_process.bash


(Just a note, if you need multiple programs to run on boot, replace "@reboot sudo python /path/to/program.py" with a bash script, and place the things you need to run on boot in that bash file.)



check_process.bash:

#!/bin/bash

process_id=`ps aux | grep "YOURPROGRAM.py" | grep -v "grep"`;

if [ -z "$process_id" ]; then

    echo "process not running for certain."

    cd /PATH/TO
    cd /PATH/TO/YOURPROGRAM.py &

else 

    echo "YOURPROGRAM.py seems to be running";

fi

The only down side is that if your program crashes, you have to wait up to a minute for the crontab to run the check_processes.bash, but otherwise is pretty solid.

Now I am also looking for how to run my script as a system service. 

John Baker

unread,
Apr 15, 2016, 9:08:17 PM4/15/16
to beagl...@googlegroups.com, bakerengi...@gmail.com
John Minton,
This looks really helpful. Also I was thinking about making an icon on the Desktop to run a bash script, probably something very easy but I am very ignorant of bash and Linux, so will have to study up on cron and bash, and here I thought all I had to learn was Python and Tkinter and Beaglebone I/O. :-)
Thanks,
John
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to a topic in the Google Groups "BeagleBoard" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/beagleboard/ULeYE9kjqZ4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to beagleboard...@googlegroups.com.

John Baker

unread,
Apr 15, 2016, 11:57:23 PM4/15/16
to BeagleBoard, bakerengi...@gmail.com, john...@ieee.org
John Minton,
I gave crontab a try and of course it didn't work. It seems like this should be a piece of cake to do. I probably did something wrong. I checked the syslog and see an error: "No MTA installed." 

My crontab file says:
@reboot sudo python /home/debian/Desktop/myProg.py
* * * * * sudo python /home/debian/Desktop/myProg.py

On boot, the Demian desktop shows up and myProg does not run. Waiting for a minute, still no joy.

Do I need to install a mail system (I'm completely ignorant, of course)?
John

Dieter Wirz

unread,
Apr 16, 2016, 4:04:21 AM4/16/16
to beagl...@googlegroups.com
On Sat, Apr 16, 2016 at 5:57 AM, John Baker <bakerengi...@gmail.com> wrote:
John Minton,
I gave crontab a try and of course it didn't work. It seems like this should be a piece of cake to do. I probably did something wrong. I checked the syslog and see an error: "No MTA installed." 

If u​
 
​have an error in ​crontab the crontab tries to send you an Email... And of coarse cannot without MTA;)

My crontab file says:
​​
@reboot sudo python /home/debian/Desktop/myProg.py
* * * * * sudo python /home/debian/Desktop/myProg.py

​The are two crontabs, users and system crontab.
Users crontab you can change with 
$ crontab -e
System crontab with
$ sudo nano /etc/crontab

If u want to run a process as root, then best is, if u add 
@reboot root /usr/bin/python /home/debian/Desktop/myProg.py
* * * * * root /usr/bin/python /home/debian/Desktop/myProg.py
to /etc/crontab

HTH 

Charles Steinkuehler

unread,
Apr 16, 2016, 7:22:27 AM4/16/16
to beagl...@googlegroups.com
On 4/15/2016 10:57 PM, John Baker wrote:
> John Minton,
> I gave crontab a try and of course it didn't work. It seems like this should be
> a piece of cake to do. I probably did something wrong. I checked the syslog and
> see an error: "No MTA installed."

In the "old" days, you would create an entry in /etc/inittab and let
init start your program at the appropriate time. This also has the
benefit that init will restart your program if it crashes for some reason.

You can do something similar with systemd, but you need to make a
small service file. Here's a fairly simple walk-through:

http://n3mesisfixx.blogspot.com/2012/08/migrate-etcinittab-job-to-systemd-in.html

--
Charles Steinkuehler
cha...@steinkuehler.net

William Hermans

unread,
Apr 16, 2016, 3:01:05 PM4/16/16
to beagl...@googlegroups.com
In the "old" days, you would create an entry in /etc/inittab and let
init start your program at the appropriate time.  This also has the
benefit that init will restart your program if it crashes for some reason.

You can do something similar with systemd, but you need to make a
small service file.  Here's a fairly simple walk-through:

http://n3mesisfixx.blogspot.com/2012/08/migrate-etcinittab-job-to-systemd-in.html

Great link Charles, thanks for sharing. I did not even think about the inittab respawn option. . .

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.

John Baker

unread,
Apr 16, 2016, 7:53:16 PM4/16/16
to BeagleBoard
Hi Dieter,
Still not working. I have a hunch that the problem is with Tkinter but can't tell. I have to run my GUI program SimB.py with the terminal program on the BBB, typing sudo python SimB.py, then it runs happily.

Here's my crontab in /etc:
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user command
17 * * * * root    cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
@reboot root /usr/bin/python /home/debian/Desktop/SimB.py
* * * * * root /usr/bin/python /home/debian/Desktop/SimB.py

and here's from the syslog file that doesn't tell me anything:

Apr 16 23:37:01 beaglebone /USR/SBIN/CRON[2293]: (root) CMD (sudo python /home/debian/Desktop/SimB.py)

Apr 16 23:37:01 beaglebone /USR/SBIN/CRON[2294]: (debian) CMD (sudo python /home/debian/Desktop/SimB.py)

Apr 16 23:37:01 beaglebone /USR/SBIN/CRON[2295]: (root) CMD (/usr/bin/python /home/debian/Desktop/SimB.py)

Apr 16 23:37:14 beaglebone /USR/SBIN/CRON[2292]: (CRON) info (No MTA installed, discarding output)

Apr 16 23:37:14 beaglebone /USR/SBIN/CRON[2290]: (CRON) info (No MTA installed, discarding output)

Apr 16 23:37:14 beaglebone /USR/SBIN/CRON[2291]: (CRON) info (No MTA installed, discarding output)


I can successfully run my program with a keyboard attached to my BBB using sudo python SimB.py, have to use the sudo, otherwise gets a Tkinter error. I just now double-checked and my GUI program SimB.py runs very happily. Cannot run SimB.py thru putty as it gives the Tkinter error.

Any ideas?
Thanks,
John

evilwulfie

unread,
Apr 16, 2016, 8:37:07 PM4/16/16
to beagl...@googlegroups.com
If this is a GUI only program you need to start your program
after the GUI is up, I don't see this check in your crontab file
Been too long since i have done this but i am sure google is your friend
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/ad44be62-e803-43e8-b131-131d16fd92f9%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


Virus-free. www.avast.com

John Baker

unread,
Apr 16, 2016, 9:16:32 PM4/16/16
to BeagleBoard
Hi Wulf Man,
My GUI is part of a simulation program. There's a lot of calculation and the GUI to allow me to enter some parameters and display the results on a graph. You're saying that I have to start up my calculation part of the program and then the GUI?
John

evilwulfie

unread,
Apr 16, 2016, 9:21:05 PM4/16/16
to beagl...@googlegroups.com
I Am saying that if your depending on the GUI for any part of your program it may expect the xwindow system to be active before
it starts, then seeing that the GUI is not running just exits.

It's hard to second guess what your program is doing here but it "may" be the issue.

try checking for the xwindow system being running before starting your program.

For more options, visit https://groups.google.com/d/optout.


Virus-free. www.avast.com

Dieter Wirz

unread,
Apr 17, 2016, 9:23:11 AM4/17/16
to beagl...@googlegroups.com
For debugging u can redirect the output into a file, eg:
* * * * * root /usr/bin/python /home/debian/Desktop/SimB.py >> /home/debian/err.txt 2>&1
(write this all in one line)

However, if your program is an X program the error will be something like:
"cannot open display"

But: All Window Managers i know provide methods to autostart a x-program....
If your WM is lxde the u will find a good explanation here:



John Baker

unread,
Apr 17, 2016, 10:56:15 AM4/17/16
to beagl...@googlegroups.com, bakerengi...@gmail.com
Really good idea evilwulfie. That, xwindows, sounds like the problem.

Now I'm thinking that I should put a startup icon on the Debian desktop to start my program, since I know that I can start it with the terminal program with sudo python myProgram.py. That has always worked, whereas I cannot start it via putty which apparently requires xwindow. It doesn't seem like this should be so hard, but probably just hard as I am not knowledgeable with Linux.
Thanks for your suggestion,
John
You received this message because you are subscribed to a topic in the Google Groups "BeagleBoard" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/beagleboard/ULeYE9kjqZ4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/5712E4F6.4030708%40gmail.com.

evilwulfie

unread,
Apr 17, 2016, 11:00:13 AM4/17/16
to beagl...@googlegroups.com

Dennis Lee Bieber

unread,
Apr 17, 2016, 12:40:32 PM4/17/16
to beagl...@googlegroups.com
On Sat, 16 Apr 2016 16:53:16 -0700 (PDT), John Baker
<bakerengi...@gmail.com> declaimed the
following:

>Hi Dieter,
>Still not working. I have a hunch that the problem is with Tkinter but
>can't tell. I have to run my GUI program SimB.py with the terminal program
>on the BBB, typing sudo python SimB.py, then it runs happily.
>

The key phrase is "GUI program".

>*Here's my crontab in /etc:*

>@reboot root /usr/bin/python /home/debian/Desktop/SimB.py
>* * * * * root /usr/bin/python /home/debian/Desktop/SimB.py
>

"cron" jobs do not have a console, much less a graphical session
manager.

>
>Apr 16 23:37:14 beaglebone /USR/SBIN/CRON[2292]: (CRON) info (No MTA
>installed, discarding output)
>
You do not have local mail transfer agent (SMTPd or equivalent) so
whatever error trace cron was going to send is being dropped on the floor.

>
>
>I can successfully run my program with a keyboard attached to my BBB using
>sudo python SimB.py, have to use the sudo, otherwise gets a Tkinter error.
>I just now double-checked and my GUI program SimB.py runs very happily.
>Cannot run SimB.py thru putty as it gives the Tkinter error.
>
putty implies a text console connection -- unless you have an X-server
running on the computer AND have configured the login via putty to use the
computer X-server (environment variable for DISPLAY pointing to the
computer) there is no graphical environment in which to open the GUI
program.

When using a direct keyboard/mouse and HDMI connection, the BBB is
running a local X-server and the (automatic) login is running a
desktop/window manager that connects to that X-server. Not sure why you'd
need the sudo -- Tkinter should be able to open a window from the account
that is running the session manager.

John Baker

unread,
Apr 17, 2016, 3:43:39 PM4/17/16
to beagl...@googlegroups.com, bakerengi...@gmail.com
I just now discovered the problem requiring sudo to start my python program. It's related to PyBBIO library code to write to the PWM interface on the BBB. I am trying to find out if there is a way around this requirement (to run the code as root) but I may be stuck with it. :-(

I get a permission denied error related to the capemgr.9 if I don't run my code as root.
IOError: [Errno 13] Permission denied: '/sys/devices/bone_capmgr.9/slots'

John

John Syne

unread,
Apr 17, 2016, 4:22:55 PM4/17/16
to beagl...@googlegroups.com
OK, so you need to learn about unix groups. In essence, you need to create a group, say “cape” and then make your userid a member of this group. After that, do the following:

sudo chown root:cape /sys/devices/bone_capemgr.9/slots

Now, as a member of the group “cape”, you are permitted to write to /sys/devices/bone_capemgr.9/slots.

Regards,
John




--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.

Dennis Lee Bieber

unread,
Apr 17, 2016, 8:55:29 PM4/17/16
to beagl...@googlegroups.com
On Sat, 16 Apr 2016 20:35:44 -0700, John Baker
<john...@ieee.org> declaimed the following:

>Really good idea evilwulfie. That, xwindows, sounds like the problem.
>
>Now I'm thinking that I should put a startup icon on the Debian desktop
>to start my program, since I know that I can start it with the terminal
>program with sudo python myProgram.py. That has always worked, whereas I
>cannot start it via putty which apparently requires xwindow. It doesn't
>seem like this should be so hard, but probably just hard as I am not
>knowledgeable with Linux.

Putty does not require an X-window environment -- it's your program
using Tkinter that needs to have an X-window environment. That is, it has
to have someplace to send the drawing commands for the GUI you want to use.
Putty is basically a text console, it does not know X-window. (In fact,
putty is likely running on a M$ Windows box and uses the Win32 runtime --
only text transfers between it and the BBB login)

http://support.objectplanet.com/esupport/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=17

When you connect via keyboard and HDMI, you are running the X-server on
localhost (the BBB). (It actually gets set up for that session on boot)

From putty -- you'd have to have an X-server running on your M$ Windows
box, and then issue command through putty to set the display to the Windows
box, before starting the Tkinter program.
>>>> *Here's my crontab in /etc:*
>>>> # /etc/crontab: system-wide crontab
>>>> # Unlike any other crontab you don't have to run the `crontab'
>>>> # command to install the new version when you edit this file
>>>> # and files in /etc/cron.d. These files also have username fields,
>>>> # that none of the other crontabs do.
>>>>
>>>> SHELL=/bin/sh
>>>> PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
>>>>
>>>> # m h dom mon dow usercommand
>>>> 17 ** * *root cd / && run-parts --report /etc/cron.hourly
>>>> 25 6* * *roottest -x /usr/sbin/anacron || ( cd / && run-parts
>>>> --report /etc/cron.daily )
>>>> 47 6* * 7roottest -x /usr/sbin/anacron || ( cd / && run-parts
>>>> --report /etc/cron.weekly )
>>>> 52 61 * *roottest -x /usr/sbin/anacron || ( cd / && run-parts
>>>> --report /etc/cron.monthly )
>>>> #
>>>> @reboot root /usr/bin/python /home/debian/Desktop/SimB.py
>>>> * * * * * root /usr/bin/python /home/debian/Desktop/SimB.py
>>>>
>>>> *and here's from the syslog file that doesn't tell me anything:*
>>>> ?
>>>> If u?
>>>> ? have an error in ?crontab the crontab tries to send you an
>>>> Email... And of coarse cannot without MTA;)
>>>>
>>>> My crontab file says:
>>>> ? ?
>>>> @reboot sudo python /home/debian/Desktop/myProg.py
>>>> * * * * * sudo python /home/debian/Desktop/myProg.py
>>>>
>>>>
>>>> ? The are two crontabs, users and system crontab.
>>>> Users crontab you can change with
>>>> $ crontab -e
>>>> System crontab with
>>>> $ sudo nano /etc/crontab
>>>>
>>>> If u want to run a process as root, then best is, if u add
>>>>
>>>> @reboot root /usr/bin/python /home/debian/Desktop/myProg.py
>>>> * * * * * root /usr/bin/python
>>>> /home/debian/Desktop/myProg.py
>>>>
>>>> to /etc/crontab
>>>>
>>>> HTH
>>>>
>>>> --
>>>> For more options, visit http://beagleboard.org/discuss
>>>> ---
>>>> You received this message because you are subscribed to the
>>>> Google Groups "BeagleBoard" group.
>>>> To unsubscribe from this group and stop receiving emails from
>>>> it, send an email to beagleboard...@googlegroups.com <javascript:>.
>>>> <https://groups.google.com/d/optout>.
>>>
>>>
>>> <https://www.avast.com/en-us/lp-esg-fav?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient&utm_term=oa-2109-v2-b>
>>> Virus-free. www.avast.com
>>> <https://www.avast.com/en-us/lp-esg-fav?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient&utm_term=oa-2109-v2-b>
>>>
>>>
>>> --
>>> For more options, visit http://beagleboard.org/discuss
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "BeagleBoard" group.
>>> To unsubscribe from this group and stop receiving emails from it,
>>> send an email to beagleboard...@googlegroups.com
>>> <mailto:beagleboard...@googlegroups.com>.
>> <https://www.avast.com/en-us/lp-esg-fav?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient&utm_term=oa-2109-v2-b>
>> Virus-free. www.avast.com
>> <https://www.avast.com/en-us/lp-esg-fav?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient&utm_term=oa-2109-v2-b>
>>
>>
>> --
>> For more options, visit http://beagleboard.org/discuss
>> ---
>> You received this message because you are subscribed to a topic in the
>> Google Groups "BeagleBoard" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/beagleboard/ULeYE9kjqZ4/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> beagleboard...@googlegroups.com
>> <mailto:beagleboard...@googlegroups.com>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/beagleboard/5712E4F6.4030708%40gmail.com
>> <https://groups.google.com/d/msgid/beagleboard/5712E4F6.4030708%40gmail.com?utm_medium=email&utm_source=footer>.
>> For more options, visit https://groups.google.com/d/optout.

John Baker

unread,
Apr 20, 2016, 12:52:28 AM4/20/16
to BeagleBoard, wlf...@ix.netcom.com
My Python program SimB.py runs fine if I start it with sudo python SimB.py using a keyboard attached to my BBB.
So I gave crontab a try again, putting it in /etc. Here's my crontab and crontab -l which seems to say my python program is running but I don't see that it has done anything, don't see anything running on my BBB 4DCAPE screen. I saw something in the CronHowTo () page about GUI's but haven't tried that yet, figuring that I would just try to start SimB.py and see what happened. So what to do next?

Thanks in advance for help,
John


>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/beagleboard/116fae1e-3ad7-4949-87ee-63a907b32cda%40googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> <https://www.avast.com/en-us/lp-esg-fav?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient&utm_term=oa-2109-v2-b>
>>         Virus-free. www.avast.com
>> <https://www.avast.com/en-us/lp-esg-fav?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient&utm_term=oa-2109-v2-b>
>>
>>
>> --
>> For more options, visit http://beagleboard.org/discuss
>> ---
>> You received this message because you are subscribed to a topic in the
>> Google Groups "BeagleBoard" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/beagleboard/ULeYE9kjqZ4/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> beagleboard...@googlegroups.com

Dennis Lee Bieber

unread,
Apr 20, 2016, 8:13:27 AM4/20/16
to beagl...@googlegroups.com
On Tue, 19 Apr 2016 21:52:27 -0700 (PDT), John Baker
<bakerengi...@gmail.com> declaimed the
following:

>My Python program SimB.py runs fine if I start it with sudo python SimB.py
>using a keyboard attached to my BBB.

Which, by default, is connected to the X-Window server running on
"localhost" (and which is also connected to the HDMI/LCD output). IOWs, you
have a full graphical environment preset for you, and Tkinter can connect
to the display server.

>So I gave crontab a try again, putting it in /etc. Here's my crontab and
>crontab -l which seems to say my python program is running but I don't see

A timed background job not connected to any form of console/display.

>that it has done anything, don't see anything running on my BBB 4DCAPE
>screen. I saw something in the CronHowTo () page about GUI's but haven't
>tried that yet, figuring that I would just try to start SimB.py and see
>what happened. So what to do next?
>
Uhm... Read that how-to page? Or maybe this:
http://ubuntuforums.org/showthread.php?t=185993

John Baker

unread,
Apr 20, 2016, 2:46:57 PM4/20/16
to beagl...@googlegroups.com, bakerengi...@gmail.com
Thanks for your help and your patience with me.
Unfortunately, still no joy and no error message but then I'm illiterate with Linux.

I forgot to mention that I am using PyBBIO to drive PWM output and to read ADC channels and it requires me to start my GUI program with sudo python SimB.py on the Debian terminal and an attached keyboard to the BBB.

I tried the following, first without the "root" in the command and then with the "root" in the command as shown in this crontab -l output:




I will set this aside for now and try systemd, to see if I can get some kind of error message at least.
John

William Hermans

unread,
Apr 20, 2016, 3:27:44 PM4/20/16
to beagl...@googlegroups.com
John,

I wrote this around 3 years ago, and should technically still work on Jessie.

http://www.embeddedhobbyist.com/2013/06/beaglebone-black-init-scripts-default-gatewayand-ntpdate/

If you ignore everything before

The fix( hack ? ) Killing two birds with one stone.

You can technically copy paste the script text I have there, remove the commands I'm running, and replace with command needed to run your script. You should also not have

use sudo inside this script file, as I believe init scripts run as root already.

Anyway I'm not 100% sure this will work, sometimes systemd steps on sysv init scripts, but it's probably worth a try.

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/5717CB19.6060207%40ieee.org.

John Baker

unread,
Apr 21, 2016, 12:04:45 AM4/21/16
to BeagleBoard, bakerengi...@gmail.com, john...@ieee.org
Some glimmer of hope: I was able to get my Python code running, at least for a few seconds. I put an icon of sorts on the BBB Debian desktop; the icon/shortcut called an sh that started my Python code using sudo python myProg.py. But unfortunately it shut down in a few seconds and an LXDE window showed up saying something about Shut Down or Cancel or Something Else but the BBB shut down and I was not able to recover from the glitch. I started from the info by Cyril Laury at http://askubuntu.com/questions/299052/how-to-execute-sh-script-from-a-desktop-shortcut and hacked around to make a startup script. So it seems that my Python program is clobbering Debian, possibly with my write to a logfile. But that's to be determined. So hopefully I can fix the problem and then I'll be happy with this means to start up my Python code and will happily forget about crontab's and systemd's.
Thanks for all the help and suggestions. You-all kept me going.
John

On Wednesday, April 20, 2016 at 11:46:57 AM UTC-7, John Baker wrote:
Thanks for your help and your patience with me.
Unfortunately, still no joy and no error message but then I'm illiterate with Linux.

I forgot to mention that I am using PyBBIO to drive PWM output and to read ADC channels and it requires me to start my GUI program with sudo python SimB.py on the Debian terminal and an attached keyboard to the BBB.

I tried the following, first without the "root" in the command and then with the "root" in the command as shown in this crontab -l output:




I will set this aside for now and try systemd, to see if I can get some kind of error message at least.
John

On 4/20/2016 5:12 AM, Dennis Lee Bieber wrote:
On Tue, 19 Apr 2016 21:52:27 -0700 (PDT), John Baker
<bakereng...@gmail.com> declaimed the
following:

John Baker

unread,
Apr 26, 2016, 4:17:40 PM4/26/16
to BeagleBoard, bakerengi...@gmail.com, john...@ieee.org
I had more trouble but finally got my desktop icon working to start up my Python program. It turned out to be quite simple. Here's my icon file:

[Desktop Entry]
Version=1.0
Exec=sudo /home/debian/Desktop/paint.sh
Name=Paint
Comment=Start up SimB.py
Encoding=UTF-8
Terminal=false
Type=Application

and here's my script to start my Python program:
#!/bin/bash
sudo python /home/debian/Desktop/SimB.py

I tried and tried and tried to get crontab running and systemd running but was stymied by Tkinter errors. Tkinter requires the sudo to run my python GUI program and I couldn't figure out how to do that with crontab and systemd. I think there must be a way to get crontab or systemd to work to start my SimB.py program on boot, but I couldn't figure out how to do so.

The problems I was having a few days ago were with the Beaglebone ADC, that it requires some delay time before re-measuring a voltage and I was running a For loop to measure the voltage four times to get an average. Somehow, the lack of a delay clobbered Debian. I cut out the For loop, finding that I didn't need to do the averaging, and was able to get the PyBBIO adcRead function to run ok. The ADC problem had not shown up previously and of course the problem would pop up when I was trying to get the startup icon to start my program. Very weird!

Thanks again for all the help.
John

William Hermans

unread,
Apr 26, 2016, 4:56:41 PM4/26/16
to beagl...@googlegroups.com
The problem with sudo, is that it's root running for a single executable - Typically. so in cases like this:

$ sudo apt-get update && apt-get upgrade

sudo wont work for both commands, only the first. But this is a very simplified example.

Additionally, one thing that many may not know, or just may not think of is: sudo is root. So if you sudo a command, that requires a path to work. Something that is only in the users path environment won't work. Because when you run sudo, you're not your user for that single command - You're root ;)

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/a8dea5d7-7e62-4ff0-9be3-51fe4cadcae2%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages