2

I made a python program to blink LED on Ubuntu installed on Raspi3b. It's running and I could blink the LED. Next steps are to blink at different times: when I power on, after ssh is active, and the end of shutdown. I am very new to Linux and system programming.

My problem is to trigger the LED blink right after SSH is active. I mean that when booting, I saw the line SSH and I want right the LED to blink right after that. I have created a *.sh file and *.service file. This source does not work after SSH is active or enabled. Once I log in from SSH and trigger sudo systemctl start my-startup.service I saw the LED blink. I don't understand why it didn't blink after SSH was active or enabled.

Because I learn a lot from here, I would like to continue on this topic, once I can blink on different status.

  1. Power On (Maybe beginning when the Linux boot started )
  2. SSH Active/enabled
  3. Boot Ends
  4. End of Shutdown

My first script is the SSH;

GNU nano 4.8                              /usr/local/sbin/my-startup.sh
#!/bin/bash

check_stat=`ps -ef | grep sshd | grep -v grep | awk '{print $2}'`
if [ "${check_stat}X" != "X" ]
then
echo "SSHD is running"
python3 /usr/local/sbin/my-startup.py
else
echo "SSHD isn't running"
fi
GNU nano 4.8                          /etc/systemd/system/my-startup.service
[Unit]
Description=Startup
After=ssh.service

[Service]
Type=simple
ExecStart=/usr/local/sbin/my-startup.sh

[Install]
WantedBy=multi-user.target
#  Blink an LED with the LGPIO library
#  Uses lgpio library, compatible with kernel 5.11
#  Author: William 'jawn-smith' Wilson

import time
import RPi.GPIO as GPIO


GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(23,GPIO.OUT)

GPIO.output(23,GPIO.HIGH)
time.sleep(1)

GPIO.output(23,GPIO.LOW)
Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
PeRGeLAdAm
  • 21
  • 2
  • What is your question? This is a Q&A forum. You need to provide a question you need an answer to. – Panki Oct 27 '21 at 13:17
  • Also: if you're already using `systemctl`, use that to ask for the `status` of the `sshd` service, instead of using that `ps` pipeline. Your question is also missing how you configured and enabled your newly created service. – Panki Oct 27 '21 at 13:18
  • OK Thank you so much. – PeRGeLAdAm Oct 27 '21 at 14:17

0 Answers0