Recreating the script
This commit is contained in:
26
pub_event[rungame,endgame](sync).ash
Normal file
26
pub_event[rungame,endgame](sync).ash
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/bin/ash
|
||||
# shellcheck shell=ash
|
||||
#
|
||||
#
|
||||
eventfile="/tmp/es_state.inf"
|
||||
|
||||
# 1. Check if the file exists and is not empty
|
||||
if [ ! -s "$eventfile" ]; then
|
||||
echo "Error: $eventfile is missing or empty."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 2. Read the payload safely
|
||||
PAYLOAD=$(cat "$eventfile")
|
||||
|
||||
# 3. Publish (using double quotes to handle spaces/newlines in the file)
|
||||
mosquitto_pub -h 127.0.0.1 -p 1883 -t /Recalbox/EmulationStation/Event -m "$PAYLOAD"
|
||||
|
||||
# 4. Optional: check if the publish succeeded
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Successfully published event."
|
||||
else
|
||||
echo "Failed to connect to mosquitto broker."
|
||||
fi
|
||||
|
||||
sleep 4
|
||||
Reference in New Issue
Block a user