Solved Run a .sh + command on startup (after reboot) automaticly

hackerpedro

Member
May 7, 2016
34
1
43
Hello,

as the topic name says, I was wondering if anyone could help me find a way to run a .sh script (example "/path/to/the/script.sh") with a command (example "/path/to/the/script.sh start") on system startup on Ubuntu Server 15.10 OS

Thanks!
 

MrKek

Member
Mar 15, 2016
56
51
56
Put your Command into the /etc/rc.local file before the exit 0 command.
 

0vert1m3

Active Member
Oct 4, 2015
216
175
91
Here m8 :D

Hello,

as the topic name says, I was wondering if anyone could help me find a way to run a .sh script (example "/path/to/the/script.sh") with a command (example "/path/to/the/script.sh start") on system startup on Ubuntu Server 15.10 OS

Thanks!
Example CentOS

Code:
#!/bin/bash

case "$1" in
start)
   /path/to/hit.sh &
   echo $!>/var/run/hit.pid
   ;;
stop)
   kill `cat /var/run/hit.pid`
   rm /var/run/hit.pid
   ;;
restart)
   $0 stop
   $0 start
   ;;
status)
   if [ -e /var/run/hit.pid ]; then
      echo hit.sh is running, pid=`cat /var/run/hit.pid`
   else
      echo hit.sh is NOT running
      exit 1
   fi
   ;;
*)
   echo "Usage: $0 {start|stop|status|restart}"
esac

exit 0

Example Debian and so on

Code:
#!/bin/bash
#
# chkconfig: 35 90 12
# description: Foo server
#
# Get function from functions library
. /etc/init.d/functions
# Start the service FOO
start() {
        initlog -c "echo -n Starting FOO server: "
        /path/to/FOO &
        ### Create the lock file ###
        touch /var/lock/subsys/FOO
        success $"FOO server startup"
        echo
}
# Restart the service FOO
stop() {
        initlog -c "echo -n Stopping FOO server: "
        killproc FOO
        ### Now, delete the lock file ###
        rm -f /var/lock/subsys/FOO
        echo
}
### main logic ###
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status FOO
        ;;
  restart|reload|condrestart)
        stop
        start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|reload|status}"
        exit 1
esac
exit 0
 

zGrav

Member
May 20, 2016
22
22
38
Hey, thanks for taking the time :) but could you be a litle bit more specific? Cause I'm a newby with Linux!

If said script is a startscript, which you can create using the examples above, you can just do this:

Under Ubuntu for example you can just do it like so:
crontab -e

e6ShgYI.png
 
Last edited:

Roberto

Member
May 14, 2015
42
0
38
can i do this to switch the user before the commend ? @reboot su ts3 cd /home/ts3/teamspeak3-server_linux_amd64 && ./ts3server_startscript.sh start ?
 

zGrav

Member
May 20, 2016
22
22
38
can i do this to switch the user before the commend ? @reboot su ts3 cd /home/ts3/teamspeak3-server_linux_amd64 && ./ts3server_startscript.sh start ?

Not needed mate, you can just login to ts3 and crontab -e directly there ;)
 
Top