I've created a bash script 'foo'. I've made that script executable with


and added it the the start-up by running

sudo update-rc.d foo defaults 80

Despite that, it doesn't appear to be working at startup. Is there a way to have my script echo messages to a log? Or is there some log that would record events/errors for this?

atm, I feel like I'm flying blind and don't really know how to troubleshoot this.

As requested, here is the content of my script:

modprobe uinput
/home/dane/dev/mangler/run.sh /home/dane/dev/mangler/dane/keys.js

the run.sh command executes program kbd-mangler.exe. When running the following in a gnome-terminal it works:

~/$ sudo bash custom_keys.sh
  • 1
    Can you post the contents of your script? – Zoredache Mar 26 '10 at 19:02
  • I see your script is referencing your home directory. Is that folder mounted and available at that point in the boot process? Have you enabled encrypted home directories? – Zoredache Mar 26 '10 at 20:12
  • Unfortunately, I don't know how to verify any of this since I'm missing a tool to troubleshoot. I can't seem to get any type of output from things leading up to or during the execution of this script. So I don't know the context in which it's running . – Dane O'Connor Mar 26 '10 at 20:43

At the beginning of your script, add this line:

exec > /tmp/debug-my-script.txt 2>&1

Reboot. Now look at that file in /tmp - it should tell you what's going on.

By the way, in init.d scripts I tend to use commands with full path (/sbin/modprobe). I've been burned so many times by the restricted PATH used by those scripts, I make no assumptions now. :)

By the way, good Bash programming links:





Take a look at the logger command.

  • Add the logger command in your script to send messages to a log file as you might use echo for debugging output to the terminal. – Dennis Williamson Mar 26 '10 at 21:09
  • 1
    Add a line like this to the beginning of your script: logger "foo started" for a simple message to be added to /var/log/syslog as an indication that your script is doing something. – Dennis Williamson Mar 26 '10 at 21:14
  • This works well. It will work in this case too. I accepted Andrei's because it let me put all the output in one place with one line of code. Your logger method mixes output into the syslog and must be filtered with grep. Regardless, +1 – Dane O'Connor Mar 26 '10 at 21:51
  • @Pauseduntilfurthernotice. Your second comment should be an answer! – Ben Oct 25 '20 at 10:39

Does the script work if you run it with sudo? If the script is setup properly the most common error I have seen relates to not setting up the environment properly.

For example it is a good practice to either set explicitly set your PATH at the start of the script or to use the full path for any commands you run.

Also is 80 the level you really need? Are you depending on something that hasn't started yet?

Does your script adequately check error levels of things you run and then respond appropriately. Good scripting and programming requires that you watch for and handle errors properly.

Put some echo status statements into your script and watch carefully as your system boots. Using logger helps since you can send output to syslog.

You could add the set -x to the first line of the script and a sleep 120 as the last line and then watch for errors. This will basically echo every statement as it is being executed to your screen and then it will wait a couple minutes so you have an opportunity to read and identify problems.

  • Will the output of echo always appear on the screen during boot? Or do I have to boot in a special way? sleeping is a good idea +1 – Dane O'Connor Mar 26 '10 at 19:35
  • I guess I was assuming you where running this on a server which would I don't think has any splash screens enabled. If this is a desktop system with a GUI then a lot of the startup messages are likely to have been hidden. – Zoredache Mar 26 '10 at 20:07
  • Unfortunately it's a desktop system. Can I write to a log in my script? Or even better, are there any logs that will automatically capture start-up errors (like not being able to find the command because of an encrypted home directory)? – Dane O'Connor Mar 26 '10 at 20:41
  • To log to a file either use logger as suggested, or just use simple redirection. echo message >> /var/log/fooscript.log – Zoredache Mar 26 '10 at 23:48

Just to add to what has been suggested.

I would also verify that the symlink /etc/rc2.d/S80foo was created and is linked correctly. If the file foo didn't exist update-rc.d should have given you an error but doesn't hurt to double check.


You can use the logger command to add entries to log files:

logger -i "Foo Starting"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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