I need to run a script at every boot. For that, I've create a .sh
file, which runs as needed using a terminal.
To make it run during boot, I followed this tutorial.
.sh
file:
#! /bin/bash
sub1="myHome/Messages"
sub2="myHome/log"
sub3="myHome/debug"
user="guy"
pass="kupelu9e"
mqtt_broker="192.168.2.100"
gnome-terminal --tab --title $sub1 -- mosquitto_sub -u $user -P $pass -h $mqtt_broker -t $sub1
gnome-terminal --tab --title $sub2 -- mosquitto_sub -u $user -P $pass -h $mqtt_broker -t $sub2
gnome-terminal --tab --title $sub3 -- mosquitto_sub -u $user -P $pass -h $mqtt_broker -t $sub3
gnome-terminal -- mosquitto_pub -u $user -P $pass -h $mqtt_broker -t "myHome/All" -m "status"
Unit file
[Unit]
Description=Runs terminalwith MQTT subs
After=network.target auditd.service
[Service]
User=guy
WorkingDirectory=/home/guy
ExecStart=/bin/bash 123.sh
running the deamon yeild an error:
guy@desktop:~$ systemctl status mqtt_subs.service
× mqtt_subs.service - Runs terminalwith MQTT subs
Loaded: loaded (/etc/systemd/system/mqtt_subs.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2023-04-11 15:12:53 IDT; 10s ago
Process: 5193 ExecStart=/bin/bash mqtts.sh (code=exited, status=1/FAILURE)
Main PID: 5193 (code=exited, status=1/FAILURE)
CPU: 273ms
Apr 11 15:12:52 desktop systemd[1]: Started Runs terminalwith MQTT subs.
Apr 11 15:12:52 desktop bash[5195]: # Failed to parse arguments: Cannot open display:
Apr 11 15:12:53 desktop bash[5197]: # Failed to parse arguments: Cannot open display:
Apr 11 15:12:53 desktop bash[5199]: # Failed to parse arguments: Cannot open display:
Apr 11 15:12:53 desktop bash[5201]: # Failed to parse arguments: Cannot open display:
Apr 11 15:12:53 desktop systemd[1]: mqtt_subs.service: Main process exited, code=exited, status=1/FAILURE
Apr 11 15:12:53 desktop systemd[1]: mqtt_subs.service: Failed with result 'exit-code'.
guy@desktop:~$
To be sure that the systemd
service runs and defined OK - I modified 123.sh
into an echo to write into a file (meaning - a very simple task), I don't get any error.
Appreciate any help
Guy