Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am working on a VM with Lubuntu 14.04,

I have created a script a.sh,

#!bin/bash
echo "aaaa" >> a.txt

And my /etc/rc.local file is as follows:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

bash /home/sentinel/a.sh
echo "hey" >> /home/sentinel/b.txt
exit 0

On rebooting my machine, I can see b.txt built with content as hey but a.txt is not being built. Can somebody please help me here?

share|improve this question
    
No, b.txt doesn't exist. By built I mean created. That means second last line of the rc.local is executed, but 3rd last isn't. @JacobVlijm –  Optimus Prime Sep 5 at 8:17

2 Answers 2

up vote 8 down vote accepted

Mention complete path where a.txt should create.

Your script should be:

#!/bin/bash
echo "aaaa" >> /home/sentinel/a.txt

I have tried this my self before posting here .

added line rc.local as

./home/sentinel/a.sh

save it and restart your PC.

share|improve this answer
2  
Wonderful. Thanks bro. –  Optimus Prime Sep 5 at 8:24
1  
Did you mean . /home/sentinel/a.sh instead of ./home/sentinel/a.sh? The first is doing source using an absolute path, the second executes the script by a relative path. –  Volker Siegel Sep 5 at 9:25
3  
Do you even bash, bro? –  Daniel Standage Sep 5 at 10:32

Missing leading / char.

#!bin/bash

should be

#!/bin/bash
share|improve this answer
1  
Sharp! however, since he is calling the script with bash /home/sentinel/a.sh it works anyway... So he escaped luckily. –  Jacob Vlijm Sep 5 at 19:26

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.