It's on Debian 11. The file PwOn.service:
[Unit]
Description=Send a message with a telegram bot
After=network.target
Wants=network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/JubiBotStartup.sh
[Install]
WantedBy=multi-user.target
With the bash script JubiBotStartup.sh being
#!/bin/bash
TOKEN="randomToken"
ID="11111111"
DT=$(date +'+%d-%m-%Y')
HR=$(date +'+%H:%M:%S')
MSG="System powered on $DT , $HR"
URL="https://api.telegram.org/bot$TOKEN/sendMessage"
curl -s -X POST $URL -d chat_id=$ID -d text="$MSG"
I've enabled the service, and so it appears like that when I put the command systemctl status. When I start the service with 'systemctl start PwOn.service' it works correctly.
However, it does not work when the system powers on or restarts, and checking its status shows the following:
PwOn.service - Send a message with a telegram bot
Loaded: loaded (/etc/systemd/system/PwOn.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2023-03-07 04:22:37 CET; 21min ago
Process: 474 ExecStart=/usr/bin/JubiBotStartup.sh (code=exited, status=6)
Main PID: 474 (code=exited, status=6)
CPU: 129ms
Mar 07 04:22:36 debian systemd[1]: Started Send a message with a telegram bot
Mar 07 04:22:37 debian systemd[1]: PwON.service: Main process exited, code=exited, status=6/NOTCONFIGURED
Mar 07 04:22:37 debian systemd[1]: PwOn.service: Failed with result 'exit-code'
~