0

This is quite a simple one. I created an rc.local file here:

/etc/rc.local

I made it executable. However, it doesn't run when I boot the server. I can see it in the directory and when I try to run it manually I get this message:

root@:/etc# rc.local
rc.local: command not found

My rc.local file reads as follows:

#!/bin/sh -e

# FUNCTIONS
function setup_logs
{
    exec > >(tee -a /var/log/deploy.log)
    exec 2> >(tee -a /var/log/error.log)
}

# COMMANDS
setup_logs
apt-get update                              # Update aptitude list
apt-get -y dist-upgrade                     # Upgrade aptitude programs
cd /etc/spider && git pull                  # Update deployment code
cd /etc/code && git pull                    # Update library code
cd /etc/code && deployment.sh               # Run deployment script
exit 0

For the life of me I don't understand where I am going wrong, can anyone give me some help?

J.Zil
  • 1,123
  • 3
  • 21
  • 29

3 Answers3

2

Ubuntu is per default using dash as Shell, and dash doesn't know the keyword function.

Try to change the shebang to

#!/bin/bash

and execute again.

According to https://wiki.ubuntu.com/DashAsBinSh/#function , it should also help if you just remove the word function and write parentheses behind the function name:

setup_logs()    {
    exec > >(tee -a /var/log/deploy.log)
    exec 2> >(tee -a /var/log/error.log)
}
etagenklo
  • 5,834
  • 1
  • 27
  • 32
0

Make sure the start script is located in your rc run level folder.

/etc/rc2.d/S22rc.local or something similar.

-1

Guys it would really really help if you google about $PATH. Once you've mastered it, you can run whatever the heck you want, GUI or not, as long as it's in the right $PATH

To the OP, you were in /etc and it is executable. To run it right there, put a dot slash in front to say 'run it from here NOW', don't just type in the filename--that was similar to 'ok run rc.local if you can find it in your $PATH'.

type 'echo $PATH' in a terminal, and you will begin to understand, especially if you want to master CLI

Now don't start putting /etc in PATH; I wanted you to see why after fixing permissions it didn't do anything differently.

jazz
  • 1
  • 1
  • The OP's question has *nothing* whatsever to do with his `$PATH` but with executing things on boot (that's what `/etc/rc.local` is for), and why his correctly placed script to do that doesn't work. Before answering a question, please try to understand what the problem is and isn't. – Dennis Kaarsemaker Mar 30 '13 at 08:30
  • But his *immediate* problem was, why is 'command not found', even after granting +x permissions so jazz was helping halfway. –  Mar 30 '13 at 09:26
  • You are Jazz, you have the same identicons ... ? – user9517 Mar 30 '13 at 09:34