Planned script to turn off screens and save on power
Create scripts that can be run from a central node in a Proxmox cluster to manage the screens of multiple laptops acting as servers. Specifically, the scripts allow you to turn off the internal screens of the laptops to save energy and prepare them for server use and turn them back on if needed. The scripts also support configuration for multiple laptops and use SSH to execute display commands on each laptop remotely. Additionally, aliases were set up for easy execution of these scripts.
This commit is contained in:
103
scripts/admin/screen_off_laptop_servers/screen_off_scripts.md
Normal file
103
scripts/admin/screen_off_laptop_servers/screen_off_scripts.md
Normal file
@@ -0,0 +1,103 @@
|
||||
### Step 1: Setting Up SSH Access
|
||||
|
||||
Ensure you have SSH access set up between your central node and all laptops. You should be able to SSH into each laptop without needing to enter a password (using SSH keys).
|
||||
|
||||
### Step 2: Create the Configuration File
|
||||
|
||||
Create the configuration file `/usr/local/bin/manage-displays.conf` on the central node with the following content:
|
||||
|
||||
```bash
|
||||
# Configuration for different laptops
|
||||
# Format: "NodeName:Host:InternalDisplay:ExternalDisplay"
|
||||
|
||||
LAPTOPS=(
|
||||
"Laptop1:192.168.1.101:eDP-1:HDMI-1"
|
||||
"Laptop2:192.168.1.102:eDP-1:HDMI-1"
|
||||
"Laptop3:192.168.1.103:eDP-1:HDMI-1"
|
||||
)
|
||||
```
|
||||
|
||||
### Step 3: Create the Main Script to Turn Off the Screens
|
||||
|
||||
Save the following script as `/usr/local/bin/manage-displays-off.sh` on the central node:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
CONFIG_FILE="/usr/local/bin/manage-displays.conf"
|
||||
|
||||
if [ ! -f "$CONFIG_FILE" ]; then
|
||||
echo "Config file not found! Please create a config file at $CONFIG_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source $CONFIG_FILE
|
||||
|
||||
for LAPTOP in "${LAPTOPS[@]}"; do
|
||||
IFS=":" read -r NODE HOST INTERNAL_DISPLAY EXTERNAL_DISPLAY <<< "$LAPTOP"
|
||||
echo "Do you want to turn off the screen for $NODE ($HOST) and prepare it for server use? (yes/y to confirm)"
|
||||
read answer
|
||||
if [[ "$answer" == "yes" || "$answer" == "y" ]]; then
|
||||
ssh $HOST "xrandr --output $INTERNAL_DISPLAY --off && xrandr --output $EXTERNAL_DISPLAY --auto"
|
||||
echo "$NODE ($HOST) screen turned off."
|
||||
else
|
||||
echo "Operation cancelled for $NODE ($HOST)."
|
||||
fi
|
||||
done
|
||||
```
|
||||
|
||||
### Step 4: Create the Main Script to Turn On the Screens
|
||||
|
||||
Save the following script as `/usr/local/bin/manage-displays-on.sh` on the central node:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
CONFIG_FILE="/usr/local/bin/manage-displays.conf"
|
||||
|
||||
if [ ! -f "$CONFIG_FILE" ]; then
|
||||
echo "Config file not found! Please create a config file at $CONFIG_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source $CONFIG_FILE
|
||||
|
||||
for LAPTOP in "${LAPTOPS[@]}"; do
|
||||
IFS=":" read -r NODE HOST INTERNAL_DISPLAY EXTERNAL_DISPLAY <<< "$LAPTOP"
|
||||
echo "Do you want to turn on the screen for $NODE ($HOST)? (yes/y to confirm)"
|
||||
read answer
|
||||
if [[ "$answer" == "yes" || "$answer" == "y" ]]; then
|
||||
ssh $HOST "xrandr --output $INTERNAL_DISPLAY --auto"
|
||||
echo "$NODE ($HOST) screen turned on."
|
||||
else
|
||||
echo "Operation cancelled for $NODE ($HOST)."
|
||||
fi
|
||||
done
|
||||
```
|
||||
|
||||
### Step 5: Make the Scripts Executable
|
||||
|
||||
Make both scripts executable:
|
||||
|
||||
```bash
|
||||
sudo chmod +x /usr/local/bin/manage-displays-off.sh
|
||||
sudo chmod +x /usr/local/bin/manage-displays-on.sh
|
||||
```
|
||||
|
||||
### Step 6: Set Up the Alias
|
||||
|
||||
Add the following aliases to your shell configuration file (`.bashrc` or `.zshrc`):
|
||||
|
||||
```bash
|
||||
# Aliases for manage-displays scripts
|
||||
alias screens-off='/usr/local/bin/manage-displays-off.sh'
|
||||
alias screens-on='/usr/local/bin/manage-displays-on.sh'
|
||||
```
|
||||
|
||||
Reload the shell configuration to apply the aliases:
|
||||
|
||||
```bash
|
||||
source ~/.bashrc # or source ~/.zshrc
|
||||
```
|
||||
|
||||
With these steps, you can now use the aliases `screens-off` and `screens-on` on the central node to control the screens of all laptops in the cluster. The scripts will prompt you for confirmation before turning the screens off or on.
|
Reference in New Issue
Block a user