How do I create a startup script in centos?

Run a script or command on Linux CentOS Startup

Looking to run a set of commands or a shell script on CentOS / RHEL / Fedora startup?

/etc/rc.local is what you’re looking for. /etc/rc.local (a symbolic link to /etc/rc.d/rc.local) is a script executed after the initial startup services have been executed.

Here’s an example of the /etc/rc.local script:

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

How to execute scripts or commands on Linux startup

Simply append the command(s) or scripts you want to run on startup to this script.

For example, we will run a script in the /opt directory called kittens.sh that prints the last system logins when Linux boots.

Create the kittens.sh Linux startup script

touch /opt/kittens.sh && echo last >> /opt/kittens.sh && chmod +x /opt/kittens.sh

Add the script to Linux startup by adding it to /etc/rc.local

echo sh /opt/kittens.sh >> /etc/rc.local

You’re done! Next time you reboot your Linux solution, the kittens.sh script will run and you will see the last user logins.

credits to http://drewsymo.com/2013/11/run-a-script-or-command-on-linux-centos-startup/

  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

How do I change my remember password options in Google Chrome

Manage your website passwords This article applies to the Google Chrome browser on Windows,...

Change time is Gmail

Correct Your Gmail Time Zone To set your Gmail time zone: Click the gear in your Gmail's...

How to speed up Windows XP use at your own risk

Warning: occasionally people break their PC badly by using this list of suggestions. Usually...

How to run cmd in escalated mode with admin rights to modify firewall

a solution: runas /user:administrator@domainname.local cmd then in the resulting command...

How do I enable auto login in Windows

This article describes how to configure Windows to automate the logon...