0

How to execute script file at startup without requiring any commands to be executed at beginning to set it up like chmod , ln -s with etc/rc.d or any other command ?

The script file should be executed at startup by just placing the script in some path.

  • 3
    Not really clear: "*without requiring any commands to be executed at beginning to set it up like chmod , ln -s with etc/rc.d or any other command *"? What is the command and why these requirements (whatever they are). Is this some kind of homework? – Jacob Vlijm Oct 13 '16 at 8:51
  • @JacobVlijm I have tried with /etc/init.d/ to run the script but it requires to create a symlink to /etc/rc.d/ , but i wanted something like if we place script file in some path it should executed @ startup. – Amruth A Oct 13 '16 at 9:01
  • Startup or log in? – Jacob Vlijm Oct 13 '16 at 16:36
  • 1
    @JacobVlijm @ startup – Amruth A Oct 13 '16 at 17:04
  • 2
    Stating the init+rc system is important, also. upstart? systemd? runit? nosh? ... – JdeBP Oct 14 '16 at 11:49
4
+50

Interesting question. Thanks for pointing out files in /etc/rc0.d you learn something new every day!

Create directory to drop your scripts into

First you need to create a directory of scripts you want automatically run at startup. I would suggest creating it within /usr/local/bin but it can be anywhere:

sudo mkdir /usr/local/bin/startup-scripts

Modify rc.local to run all your scripts

Then type gksu gedit /etc/rc.local to edit the startup script that has sudo powers.

Before the last line that says exit 0 copy and paste these lines:

for SCRIPT in /usr/local/bin/startup-scripts/*
do
    sudo chmod +x $SCRIPT
    $SCRIPT
done

Optionally, for every script in the startup-scripts directory, I would put in something like:

echo "running script xyz within /usr/local/bin/startup-scripts"

as this message will appear in /var/log/syslog file and document your system setup.

| improve this answer | |
1

You can try to put the command in /etc/rc.local. Just add the command or the script path before 'exit' line.

| improve this answer | |
1

Easy. Edit the /etc/environment file (with admin priveleges using sudo of course) and append the directory containing your script(s) to your system path. Then, at least in Ubuntu, it's a piece of cake: type Startup Applications in the search bar and just add a new entry in the popup with the name of the script. Reboot and the magic will happen.

| improve this answer | |
1

You could add a crontab @reboot to run the script, it should work with any init system.

As root :

crontab -e

@reboot /path/to/your/script

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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