Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
run with ./rc.local or /etc/rc.local –  Laurentiu Roescu Mar 25 '13 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. –  Laurentiu Roescu Mar 25 '13 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 –  James Willson Mar 25 '13 at 13:35
    
@LaurentiuRoescu /etc/init.d/rc.local does exist and is executable –  James Willson Mar 25 '13 at 13:36
    
probably /bin/sh does not support function keyword. –  Laurentiu Roescu Mar 25 '13 at 13:40

3 Answers 3

up vote 2 down vote accepted

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)
}
share|improve this answer

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

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

share|improve this answer
    
In rc2.d I have this: README, S50rsyn, S70pppd-dns, S99grub-common, S99rc.local, S45landscape-client, S70dns-clean, S75sudo, S99ondemand –  James Willson Mar 25 '13 at 13:38
    
I believe that is not the problem then –  James Willson Mar 25 '13 at 13:38
    
Also is your /etc/rc.local marked +x –  darkstar2002 Mar 25 '13 at 13:45

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.

share|improve this answer
    
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 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 '13 at 9:26
    
You are Jazz, you have the same identicons ... ? –  Iain Mar 30 '13 at 9:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.