WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

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

Offline risshuu

  • Newbie
  • *
  • Posts: 19
Command not running on startup
« on: November 14, 2016, 06: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, 06: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, 09:03:53 AM »
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, 03: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, 03:38:26 PM by risshuu »

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: Command not running on startup
« Reply #4 on: November 14, 2016, 06: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 14, 2016, 10:09:49 PM »
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 14, 2016, 11:09:52 PM »
/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 15, 2016, 10:05:43 PM »
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 15, 2016, 10:15:49 PM by risshuu »

Offline risshuu

  • Newbie
  • *
  • Posts: 19
Re: Command not running on startup
« Reply #8 on: November 15, 2016, 11:07:47 PM »
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.