Glam Prestige Journal

Bright entertainment trends with youth appeal.

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.

9

4 Answers

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.

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

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.

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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