### Scripting

Raspberry Pi Scripting Hints
Example Create an executable script
Login
Login as pi
Create a script folder
mkdir /home/pi/myscriptfolder
Set script folder as default
cd /home/pi/myscriptfolder
Create a new script using the nano editor
sudo nano myscript
Content of the script
As an example a Java Jar is executed
#!/bin/bash
# My Script Description
echo "This is my Script..."
java -jar myjavaapplication.jar
Make the script executable:
sudo chmod 755 myscript
Test the script
/home/pi/myscriptfolder/myscript
Note 1
If the application should run the background, add a & to the java command in the script file:
java -jar myjavaapplication.jar &
Note 2
To launch the script at start-up edit the file "rc.local" needs to be edited.
sudo nano /etc/rc.local
Add the following line:
/home/pi/myscriptfolder/myscript
Example script waiting for Return
#!/bin/bash
echo "Press Return to continue"
read dummyinput
echo "OK, will continue..."
Example for a 2 seconds Pause
#!/bin/bash
echo "Starting..."
sleep 2
echo "OK, will continue..."
Create an executable script
Login as pi, create a script folder and edit the bash file
mkdir /home/pi/myscriptfolder
cd /home/pi/weathercubeone
sudo nano script_copyright
Content of the Script:
#!/bin/bash
# Script to show copyright message on weathercubeone
echo "WeatherCubeOne show copyright..."
mosquitto_pub -h localhost -t weathercubeone/copyright -m ""
Make the script executable.
$sudo chmod 755 script_copyright
Create a switch in Domoticz
Create a new Virtual Switch
Edit and define as action:
script:///home/pi/weathercubeone/script_copyright

Changed: 2018-06-07 09:17, Category: Raspberry Pi, File: T6C234M1715.htm, ID: 1715