I am trying to set an auto run on my shell script (named driver_check.sh) which will trigger upon rebooting the driver.

Basically, my script is as shown below:

echo "Start script"
    now=$(date +"%T")
echo "======== LOG EVENT CHECKING ========" >> $LOGFILE_HOME
echo "DATE: $(date +%Y-%m-%d ) $now" >> $LOGFILE_HOME
echo "------------------" >> $LOGFILE_HOME
for loop in {1..3}
        echo $loop
        echo "Loop $loop" >> $LOGFILE_HOME
        now=$(date +"%T")
        echo "Current time : $now"

        if grep -iq success /var/opt/mydriver/log/driver.log
            echo "ok"

            if [ $loop = 3 ]
                    #send email
                    mail -s "Fail to restart/reboot" myemail@domain.com

                    echo "Fail"
                    echo "Fail" >> $LOGFILE_HOME
                    echo "An email has sent>> $LOGFILE_HOME

        ((loop ++));
        sleep 3


I have tried adding this line at the beginning of the script

chmod 755 driver_check.sh

I have also moved the file to /etc/init.d The script still do not auto run when I restart the driver. What else should I do to make it works? Really appreciates any advice you guys can offer.


Puting the script in /etc/init.d will not be enough to execute it at reboot. Depending of your linux distribution, you should check for runlevel and how to run a script at startup (either init.d, systemd, rc.d ....)

On redhat/CentOS < 7, you have chkconfig[1] to manage such things, adding the correct header to you script, it will automagically creates the correct link so that script will be launch at correct runlevel.

[1] on redhat 7 and CentOS 7 this tool don't manage systemd service

  • My linus distrbution is SUSELinux 3.0.76 (I think?). What do you mean by check for runlevel? Is it creating symbolic link? How do I know which run level? This code chkconfig, how do I use it? I tried typing into the command line but all I see is on/off variables that I do not understand. Really appreciates your reply
    – Kristin.Y
    Dec 15 '15 at 2:10

You can use udev to execute command on hardware change. I can't say more how to use it but it will certenly help you.

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.