Raspberry PI Shutdown on button press

After adding a button with resistors (there are lots of other resources about that). I wanted a version using systemd.

The gpio testing script is using wiringpi.

Add this as /root/pin-shutdown.sh:


pin=29  # pin 40 (internal: 21) on raspi layout
gpio mode $pin in
gpio wfi $pin both
logger Shutdown button pressed
shutdown -h now

gpio wfi 21 both is blocking until the pin changes its state.

And the systemd service as: /etc/systemd/system/button-shutdown.service:

Description=button shutdown service



Enable the systemd service with: systemctl enable button-shutdown

start script with systemd

I wanted to shoot as many photos as possible with a raspicam. But no photos at night (the hours are in UTC). Save the file as /root/shoot.sh and set the file as executable.


mkdir /root/images

while true
  sleep 1
  if (( `date +%H` < 21 )); then
    if (( `date +%H` > 2 )); then
      /opt/vc/bin/raspistill -o /root/images/`date +%s`.jpg -rot 180

Archlinuxarm doesn't have a rc.local file. So I had to use systemd to start the script and keep it alive:

Description=Camera shooting service



Save as /etc/systemd/system/camera.service and enable it with systemctl enable camera.service. It will start now at the next boot.

Find active servers in subnet

I needed an org-mode table with a list of all currently used IP addresses in a subnet.

#+BEGIN_SRC bash
  nmap -sP | grep "scan report" | cut -d" " -f5 | sort -V

| |
| |
| |
The nmap command returns for each server 2 lines.
The line with the IP address contains "scan report".
cut splits the IP address from the line and sort -V sorts by IP address.

To run a command in org-mode you press C-c C-c inside the region and answer the security question with y.