Startup Linux Scripts PFC/TP

Sometimes it is required to execute a script on startup, here are instructions to accomplish this on the PFC200.

From shell, type:
nano myscript1.sh

#!/bin/bash
#  automaticaly run script at startup 
#> cd /etc/rc.d
#> ln -s ../init.d/myscript1 S99_myscript1

case $1 in
    start)
        /home/user/myscript1.sh &
        ;;

    *)
        echo "Usage: ${0} start"
        exit 1
        ;;
esac
exit 0

Very important to know, that you need to make this script file directly in PFC, because you need UNIX format file.

If you make this file in Windows and scp it to the controller, then you will need to run the following command;

cat myscript.sh | tr -d ‘\r’ > myscript1.sh

4 Likes

Another method is using CRON;

From the shell, type:
nano /home/myscript.sh

Edit the file to restart the USB controller for example;

echo "1-1" > /sys/bus/usb/drivers/usb/unbind
echo "1-1" > /sys/bus/usb/drivers/usb/bind

Make script bootable;
chmod 777 /home/myscript.sh

Open Crontab with nano editor (much easier to use than vi for me);
export VISUAL=nano; crontab -e

Then edit the file in nano to run the script after 60 seconds;

* * * * *  /usr/sbin/logrotate -s /var/log/logrotate.status /etc/logrotate.conf
@reboot sleep 60 /home/myscript.sh
2 Likes

Be aware of the cpu load on the conrollers when starting more than one user-application - maybe need to wait in between. This was the case for me using Node.js + Grafana on the CC100.

3 Likes

Hey Kurt, thanks for this useful information.
You can also use Notepad++ on your computer to edit the script.
For this you need to go in Settings / Preferences / New Document, and set the format to Unix.
(It does not work on previously created files, you need to create one).

You can check if this is ok with View / Show Symbols / Show all characters. For a Unix file, you should see only “LF” (line feed) at the end of the file.

You can also install a FTP plugin in Notepad, which is very useful (“Nppftp”).

2 Likes

Good morning Quentin,

Looking back at this post, Notepad ++ has an option (not sure if it was there before) to change format quicker, by just right-clicking on the option in the right bottom corner:

image

Of course that changes the format for this file only.

Hope it helps!

1 Like

Thanks for the hint !