How can I make this script run in the background?

Lolis4TheWin
#!/bin/bash

# Get the battery percentage for battery 0
battery0_percent=$(cat /sys/class/power_supply/BAT0/capacity)

# Get the battery percentage for battery 1
battery1_percent=$(cat /sys/class/power_supply/BAT1/capacity)

# Threshold level
threshold=10

# Check if either battery is less than 10%
if [ "$battery0_percent" -lt "$threshold" ] || [ "$battery1_percent" -lt "$threshold" ]; then
    # Display a Zenity warning
    zenity --warning --text "Battery level is below 10% on one or both batteries!"
fi

This script sends a warning when one of my batteries is below 10%.

How can I run this script in the background, on a Linux system, so it will notify me when it has to?

juliethefoxcoon

You have 2 ways to do this:

Add an ampersand after the command

./battery-script.sh &

This will keep the command running even after you close the terminal, by spawning a subprocess within your shell

If you want something that persists even after you log out the shell, you can add nohup before the command

nohup ./battery-script.sh

This will also redirect the output of the command into a file called "nohup.out"

If you want to go even further and run this script at startup, you also have a few different options:

If you want this script to start up every time you start your display server:
With x11:

Add the line ./battery-script.sh & to the end of your ~/.xinitrc for the script to be run every time you start up x11(probably what you want in this scenario, given how you have a line for a zenity warning)
If you run wayland, it depends on your wm, with sway it's .config/sway/config.d/autostart_applications

If you want to run the script before your display server even starts, you can put the script in /etc/profile.d

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I make a Python script standalone executable to run without ANY dependency?

How can I make a background in SwiftUI translucent?

How can I make a background overlaying the recyclerView?

How can I make my bash script wait 30 minutes to run?

How can I make a linux background process (in c) that launches a Python script

I have a script that runs forever, how can I run it at startup in the background on macos?

How can I make a script run automatically after gdm login and logout?

How can I make GNU screen run a command or script every time I create a new window?

How can I make the server check a site every time? How can I run a script on a server?

How can I run a Java program in background?

How can I make firefox run in the background like chromium?

How can I run OpenVPN as root in the background, in a script?

How can make script run?

How can I run background script dynamically in chrome extension?

How can I make my sed script run faster?

How can I make a script that can be downloaded and run by a non-technical Mac user by double-clicking?

How can I make this shape with background gradients?

How can I make the entire background clickable?

How can i make a jquery script NOT run until the visible part of it is loaded? (actually on the screen of the user)

How can I make a Google Sheet script run reliably on Samsung tablets?

How can i run my python script in the background in my VPS

HOW TO Make Python Script run from startup in background on windows

How can i run script, command on background and kill for request?

How i can run sh script inside docker-compose file in background?

How can I make my script run on multiple sheets on Google Sheets ? I'm inserting rows with data and need it to run on multiple sheets

How can i run a loop procedure in background?

How can i make my request run in background while filling other EditTexts (Thread)?

How I can make animation for background?

How to make this script run in the background?

TOP Ranking

HotTag

Archive