WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Command not running on startup  (Read 2309 times)

Offline risshuu

  • Newbie
  • *
  • Posts: 19
Command not running on startup
« on: November 14, 2016, 09:28:36 AM »
I am trying to run the following command on startup.
Code: [Select]
sudo -u bob -H python /home/bob/fauxmo.pyI am running piCore v 8.0.  I am not using a desktop environment.

I can run the code above as root no problem, but it will not run it when I put it in /opt/bootlocal.sh.

How can I get this to run every time the machine is started?

Thanks

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: Command not running on startup
« Reply #1 on: November 14, 2016, 09:37:50 AM »
Omit the  sudo  part, as  bootlocal.sh  already runs with root privileges.
Download a copy and keep it handy: Core book ;)

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Command not running on startup
« Reply #2 on: November 14, 2016, 12:03:53 PM »
Does user bob and /home/bob exists?
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline risshuu

  • Newbie
  • *
  • Posts: 19
Re: Command not running on startup
« Reply #3 on: November 14, 2016, 06:30:55 PM »
Misalf: I don't want it run as 'root', I want it to run as 'bob'.

bmarkus: Yes, the user and his home directory exists.  I can run the command as root with no problem after the machine has started up.  I want this to run every time I turn on/reboot the machine.  I want it to run as 'bob', and not root.

I can't think of any other way of doing it.

Thanks
« Last Edit: November 14, 2016, 06:38:26 PM by risshuu »

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: Command not running on startup
« Reply #4 on: November 14, 2016, 09:33:48 PM »
Code: [Select]
TCUSER="$(cat /etc/sysconfig/tcuser)"
su "$TCUSER" -c "python /home/bob/fauxmo.py"
Download a copy and keep it handy: Core book ;)

Offline risshuu

  • Newbie
  • *
  • Posts: 19
Re: Command not running on startup
« Reply #5 on: November 15, 2016, 01:09:49 AM »
Misalf:  Thank you for the reply :D.  It does work, but I wanted to run it as a different user that I created on the box, not as tc.
 :-\

Any other ideas?

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: Command not running on startup
« Reply #6 on: November 15, 2016, 02:09:52 AM »
/etc/sysconfig/tcuser  contains the current user name, not necessarily  tc .
You can use the  user=  boot code to change that.
Otherwise,
Code: [Select]
su bob -c "python /home/bob/fauxmo.py"
should work.
Download a copy and keep it handy: Core book ;)

Offline risshuu

  • Newbie
  • *
  • Posts: 19
Re: Command not running on startup
« Reply #7 on: November 16, 2016, 01:05:43 AM »
Thank you!  I set "bob" up as a system account so it wasn't working because he had no default shell (afaict).  I just added
Code: [Select]
-s /bin/bash to the code you gave me and it looks like it works.

Thank you so much!
« Last Edit: November 16, 2016, 01:15:49 AM by risshuu »

Offline risshuu

  • Newbie
  • *
  • Posts: 19
Re: Command not running on startup
« Reply #8 on: November 16, 2016, 02:07:47 AM »
Looks like I spoke too soon.  While it did run at the cli when run as root, it did not run when I restarted my pi.

Thanks for the help, though.