linux - make scripts run only one instance when a user logs in -


i trying run few bash scripts continually when logged in linux mint install. adding them startup applications doesnt appear work, because not running when check. dont want create multiple instances of scripts adding them .bashrc or cronjob seems out. other suggestions?

an example script (warns me when battery below 30%):

#!/bin/bash while : #echo "starting script: $(date)">>battery_log  percent=$(upower -i /org/freedesktop/upower/devices/battery_bat0| grep -e "percentage" | grep -o '[0-9]\+') cpu_temp=$(cat /sys/class/thermal/thermal_zone0/temp | awk '{print "deg c: "$1/1000}') discharge=$(upower -i /org/freedesktop/upower/devices/battery_bat0| grep -e "state") is_discharging=$(echo $discharge | grep -c discharging)  #echo "$percent" #echo "$cpu_temp"    #echo hello | grep -c #if [echo $discharge | grep -c discharging -gt 0 ];     #echo "success" #fi  #echo "$discharge" if [ "$is_discharging" -gt 0 ];      echo "---discharging: $(date)">>battery_log     if [ "$percent" -lt  30 ];          #exec 2>>/home/king/scripts/battery_log.txt         export display=:0         #export xauthority=~otheruser/.xauthority         #kdialog --msgbox "$(upower -i /org/freedesktop/upower/devices/battery_bat0| grep -e "state|to\ full|percentage") \n cpu temp:      $(cat /sys/class/thermal/thermal_zone0/temp | awk '{print "deg c: "$1/1000}')"         kdialog --title "low battery" --passivepopup "$(upower -i /org/freedesktop/upower/devices/battery_bat0| grep -e "state|to\ full|percentage") \n cpu temp:      $(cat /sys/class/thermal/thermal_zone0/temp | awk '{print "deg c: "$1/1000}')" 20     fi fi  sleep 300 #5min done 

before run script, check if instance of script running.

pgrep script.sh.

if it's running, can exit, otherwise continue script.

pgrep script.sh && exit should trick.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -