Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there a way to run a .sh script ONCE when I boot? I know about the init.d folders, but there seems to be some weird special layout you must use for scripts there.

I only want to run two quick lines of code, nothing huge. I'm running the latest Raspbian.

Any tips?

share|improve this question

closed as off-topic by MadHatter, Iain, MichelZ, Jenny D, Tom O'Connor May 13 at 14:02

  • This question does not appear to be about professional server, networking, or related infrastructure administration within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

    
We don't consider RPis to be servers within the meaning of ServerFault. We consider Super User, Raspberry Pi or Unix & Linux to be better suited to the enthusiast nature of this device. –  Iain May 13 at 12:00
    
I don't know if it works in Raspbian, but some crontabs allow you to specify time as @reboot. –  Jenny D May 13 at 13:53
add comment

1 Answer 1

up vote 1 down vote accepted

This is NOT standard compliant, but it works:

Create a new file in /etc/init.d -->

#!/bin/bash
case "$1" in
start)
    yourcodehere 
    ;;
esac

exit 0

then set the executable bit and remove all other permissions: chmod 700 /etc/init.d/filename

and then configure your service to autostart: update-rc.d filename defaults

Hope this helps, Tobias

share|improve this answer
    
Seems to have done it, thanks :) –  user3433131 May 13 at 12:01
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.