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?

5
  • run with ./rc.local or /etc/rc.local Mar 25, 2013 at 13:20
  • And check if /etc/init.d/rc.local exists. If I remember correctly /etc/init.d/rc.local executes /etc/rc.local in Ubuntu. Mar 25, 2013 at 13:31
  • @LaurentiuRoescu when I do ./rc.local it says No such file or directory and when I do /etc/rc.local it says /etc/rc.local: 4: /etc/rc.local: function: not found
    – J.Zil
    Mar 25, 2013 at 13:35
  • @LaurentiuRoescu /etc/init.d/rc.local does exist and is executable
    – J.Zil
    Mar 25, 2013 at 13:36
  • probably /bin/sh does not support function keyword. Mar 25, 2013 at 13:40

3 Answers 3

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)
}
0

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

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

3
  • In rc2.d I have this: README, S50rsyn, S70pppd-dns, S99grub-common, S99rc.local, S45landscape-client, S70dns-clean, S75sudo, S99ondemand
    – J.Zil
    Mar 25, 2013 at 13:38
  • I believe that is not the problem then
    – J.Zil
    Mar 25, 2013 at 13:38
  • Also is your /etc/rc.local marked +x Mar 25, 2013 at 13:45
-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.

3
  • 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. Mar 30, 2013 at 8:30
  • But his immediate problem was, why is 'command not found', even after granting +x permissions so jazz was helping halfway.
    – user167073
    Mar 30, 2013 at 9:26
  • You are Jazz, you have the same identicons ... ?
    – user9517
    Mar 30, 2013 at 9:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .