I am running Linux 4.9.11-1.0.0 on my iMX7 dual development board. I have a test.sh file that I would like to run at startup. It currently only has a bunch of echo statements in it (just for testing purposes).

When I flick the switch on the board to turn it on, I see a bunch of initialization stuff come up. I would like the echo statements in my test.sh file to also be displayed in this initialization sequence on startup. Eventually once this is working, the plan is to do real stuff in place of the simple echo statements. I just want to make sure the script is running on startup at this point.

So far I have created the test.sh file and I am able to run it manually after the board has booted up. I have added the following to my /etc/rc.local file before the exit statement at the end:

sh '/home/root/test.sh'

I have verified that this rc.local file has #!/bin/sh -e at the top. I have also done:

$ chown root /etc/rc.local
$ chmod 777 /etc/rc.local

Once this was all done, I verified that it should be working properly by typing:

$ /etc/init.d/rc.local start

Everything is working as expected up until this point and I am seeing the echo statements when I do that last step. However, when I go and try to reboot the board, I do not see the echo statements at all in the printed initialization stuff.

What am I missing? Maybe it is actually running on startup but I just don't see the output for some reason?


2 Answers 2


If you've done everything such as chmod +x /etc/rc.local then your command is running, it's just not getting logged anywhere that you can see it.


This is my /etc/rc.local:

$ cat /etc/rc.local
touch /var/lock/subsys/local
echo "hickory stick"

Here I've used the modified Bash which logs to syslog which I discussed in this other U&L Q&A titled: Sending bash history to syslog.

When my system boots I see the following message getting logged via Bash:

/var/log/bash-log/ centos7 rc.local: hickory stick

But no where else. To get this to log to syslog/rsyslog you typically can use the logger command to do so:

$ logger hi

You can then see it in your /var/log/messages or /var/log/syslog or journal -xef. Here I'm using journald:

$ journalctl -xef
Jul 24 20:23:04 centos7 bash[1629]: HISTORY: PID=1629 UID=0 USER=root CMD=man logger
Jul 24 20:23:24 centos7 bash[1629]: HISTORY: PID=1629 UID=0 USER=root CMD=logger hi
Jul 24 20:23:24 centos7 vagrant[1811]: hi

You should be able to use logger to capture output from commands in scripts like so:

$ cat /etc/rc.local
touch /var/lock/subsys/local
echo "hickory stick" | logger

Now when we reboot:

$ journalctl -xef
Jul 24 20:31:41 centos7 bash[1629]: HISTORY: PID=1629 UID=0 USER=root CMD=journalctl -xe
Jul 24 22:24:00 centos7 logger[1286]: hickory stick
Jul 24 22:24:00 centos7 sshd[1270]: Server listening on port 22.
Jul 24 22:24:00 centos7 sshd[1270]: Server listening on :: port 22.
Jul 24 22:24:00 centos7 systemd[1]: Starting Permit User Sessions...

We see our message there via logger that we added to /etc/rc.local.

Extra info

logger is a pretty useful and you can have it log to a file instead of via the -f switch, you can also control the tag that shows up in the logs with the -t switch.

$ logger -t "smurfs" hi
$ journalctl -xe | grep smurfs
Jul 24 20:38:24 centos7 smurfs[1764]: hi



Have you tried putting it in your .bash_profile ? This is a file that gets run on login. So it won't turn on when everyone logs in or technically at startup... but if you are using one user this might be a simple solution for what you need.

Go to your home directory, which if you're root is actually /root not /home/root (at least in the distro's I'm familiar with. Perhaps "echo $HOME" to confirm your home directory.)

Once there, do:

ls -la

Should see a hidden file called .bash_profile Open it up and take a look. Most have some instructions commented in. You can run your script directly there or just have it invoked with with:

sh '/home/root/test.sh'

  • 2
    Just want to point out that login is distinct from startup
    – Jeff Schaller
    Jul 24, 2018 at 22:02
  • @JeffSchaller which is fair, and I do mention in passing. I can edit to be more verbose if this is really bothering you.
    – bashCypher
    Jul 24, 2018 at 22:06

You must log in to answer this question.

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