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.
- Power On (Maybe beginning when the Linux boot started )
- SSH Active/enabled
- Boot Ends
- 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)