Skip to content

Autostart scripts

tunning scripts on system startup

method depends on distro / desktop mgr
cinanaom == X11 + GNOME +

settings > startup apps == GUI mgr
these gui alters desktop files in /home/ward/.config/autostart/
= launch on logon ?
≠ launch on suspend / resume ?

for all users : in /etc/xdg/autostart
( after boot is finished ? on each logon ? )

Running scripts before and after suspend with systemd

https://blog.christophersmart.com/2016/05/11/running-scripts-before-and-after-suspend-with-systemd/ [ZOTERO]

man systemd-suspend.service

put an executable script of any name under :
/usr/lib/systemd/system-sleep/ (root )
that checks whether the first argument is pre (for before the system suspends) or post (after the system wakes from suspend).

#!/bin/sh  
if [ "${1}" == "pre" ]; then  
  # Do the thing you want before suspend here, e.g.:  
  echo "we are suspending at $(date)..." > /tmp/systemd_suspend_test  
elif [ "${1}" == "post" ]; then  
  # Do the thing you want after resume here, e.g.:  
  echo "...and we are back from $(date)" >> /tmp/systemd_suspend_test  
fi

sudo su -
cd /usr/lib/systemd/system-sleep/

users of Debian take notice that the path to place the files under for that distribution is /lib/systemd/system-sleep/
without the /usr.
Although this actually is properly documented with the correct path in the man page, it is a detail which is easy to miss.

sudo su - 
cd /lib/systemd/system-sleep/
echo aa > st.sh
# xed will not work here
nano st.sh       
# replace "aa" with script above
chmod 777 st.sh
#verify : 
ls -ltr 

test by supend /resume
cat /tmp/systemd_suspend_test
OR
cd /tmp/
ls sys*
cat systemd_suspend_test

issue

root@lapwm:/tmp# cd /lib/systemd/system-sleep/
root@lapwm:/lib/systemd/system-sleep# ./st.sh
./st.sh: 2: [: unexpected operator
./st.sh: 5: [: unexpected operator

=> adjustment to the script ; single = instead of double == :
if [ “${1}” == “pre” ]; then ==> if [ “${1}” = “pre” ]; then