Run Linux Shell Script On Boot

linux run script at startup centos
ubuntu 18.04 run script on startup
how to add startup scripts in redhat linux 7
how to run a shell script as a service in linux
linux run script on startup as root
run command at startup linux
linux run python script on startup
linux startup

I have a Shell script that I want to run on boot. Every time that I start the device It'll run the script in the background. The script contains a while true loop and suppose to run constantly, at least until the device will be turned off. This is the script :


cd /home/.../
while true 
  sh ./
sleep 1

After of plenty of searches I've came up with too much information which made a salad in my head. I've been advised to get to this folder /etc/init.d and put down my script there by using special pattern (LSB-compliant) which looks like this :


start () {
    echo "application started";
    ./helloworld  # you should use an absolute path here instead of ./

stop () {


case "$1" in
        echo "Usage start|stop";

exit $?

Make the script executable by chmod +x, then make A symbolic link for the file by typing ln -s /etc/rc.d/init.d/ /etc/init.d/rc5.d/S90run_update

This supposed to be the "hard way" while the "easy way" is putting my script in a folder /etc/rc.local where it shall boot my script after the main boot process.

Well, I don't have this kind of folder. What I to have in etc folder is rc.d which leads to sub folders : init.d rc0.d rc1.d rc2.d... rc6.d

If the solution is the hard way by writing the code above, what is the minimum that I need to include in it? since I see different type of codes which include ### with descriptions and run levels I have a Linux Red Hat 4.6.3-2.

OK I think I understand. start a konsole session, then look for a hidden file called .bash_profile. If you do not find it in your home directory then it does not exit. Create it with pico (use pico .bash_profile). If the file exist, edit it with a link to your script. The next time you log into your system that file will run.

HOpe this helps.

How to run a shell script at startup, On an Amazon S3 Linux instance, I have two scripts called start_my_app and stop_my_app which start and stop forever (which in turn runs my  If you want to run your bash script from anywhere, as if it were a regular Linux command, add the location of your shell script to the PATH variable. First, get the location of your script's directory (assuming you are in the same directory), use the PWD command:

in DEBIAN script should have at top

# Provides:          SCRIPT_NAME_HERE_NO_PATH
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.


then in shell must enable rc system links

update-rc.d SCRIPT_NAME_HERE_NO_PATH defaults
update-rc.d SCRIPT_NAME_HERE_NO_PATH enable

How to Auto Execute Commands/Scripts During Reboot or Startup, Note: We will assume the use of Bash as main shell for logon and logout events. methods to execute a command or run scripts during startup:  For CentOS, we use file ‘/etc/rc.d/rc.local’ instead of ‘/etc/rc.local’. We also need to make this file executable before adding any script or command to the file. Note:- When executing a script at startup, make sure that the script ends with ‘exit 0’. Method 2 – Crontab method

1. Add below lines in intit.rc: 
  chmod 0755 /system/bin/shellscript_name  //giving permissions to your shell_script
  start name_your_service      //starting your shellscrip

  service name_your_service /system/bin/shellscript_name     
      class main
      user root
      group shell system 
      seclabel u:r:shell:s0

2. Goto the vendor directory and create your shell script under system/bin/shellscript_name.

3. Add your shell script under Android MakeFile:
include $(CLEAR_VARS)
LOCAL_MODULE        := module_name
LOCAL_MODULE_OWNER  := owner_name
LOCAL_MODULE_TAGS   := optional
LOCAL_SRC_FILES     := path to your .sh

How to Run a Command on Startup in Linux, Create a script such as "" using your favorite text editor. Save the file in your /etc/init.d/ directory. Change the permissions of the script (to make it  Server-based Linux distributions will run the default shell such as Bash after the user logged in at the console instead of loading the desktop environment. You can choose to automatically run your programs or scripts at any of the above stages. Methods to automatically run program on Linux startup:

How to automatically execute shell script at startup boot on systemd , There maybe various reason why you might want to execute shell script during Linux startup like for example to start a particular custom service,  How do I run .sh file shell script in Linux? The procedure to run the .sh file shell script on Linux is as follows: Set execute permission on your script: chmod +x; To run your script, enter:./ Another option is as follows to execute shell script: sh OR bash

command line - How do I run a script at start up?, #!/bin/sh /path/to/my/ Make it executable. chmod ugo+x /etc/init.d/​myscript. Configure the init system to run this script at startup. The main reasons are that there would be no more starting up the server, logging in over ssh, entering a password, getting a root shell and then manually executing script after script. Instead, harness the power of cron, and set your system to automatically run these scripts at startup! Here’s how to do it.

How to Run Linux Commands and Scripts Automatically on a , Running apps and scripts automatically on startup can be useful for automating You can replace it with your own command or with full path of your bash script. Just pick an arbitrary executable file, even a shell script, and boot the kernel with the command line parameter: init=/path/to/myinit Towards the end of boot, the Linux kernel runs the first userspace executable at the given path.

  • Look under /etc/rc.d. There should be an rc.local. If there isn't, you can create one. In other words, you want a script file, /etc/rc.d/rc.local, not a folder, /etc/rc.local.
  • I was thinking that I might need to create rc.local. It something that the OS is familiar with? I just create one by using "vi"?
  • Yes the OS knows about it.
  • Not knowing what your script actually does: Can't you just schedule it to -- for instance -- run every minute? (you can do this with cron)
  • Which distribution are you running? You said Red Hat 4.6.3-2, but that is not likely to be correct. What does /etc/redhat-release say?
  • I'll try your solution too. Fortunately the previous solution with the rc.local file was the best one. The problem from the first was that I didn't have this file in my rc.d directory. Eventually I understood that I could create this file on my own which eventually solved this case.