Quickly send commands to your Linux devices using scripts from the console. Whether you need to install apps, check services, or manage Wi-Fi, this guide helps you push scripts, track results, and automate actions with ease.
Send commands to your Linux devices with scripts. You can use up to 16,600 characters per script.
In this article:
- Sending Commands
-
Debian-based Commands
- Install an App
- Uninstall an App
- Check the Status of a Service
- Modify Files
- Remove File
- CPU, Memory Usage
- Reboot
- Check Wi-Fi Settings
- Modify Wi-Fi Settings
- Add Wi-Fi
- Remove Wi-Fi
- Lock Screen
- Turn Bluetooth On
- Turn Bluetooth Off
- Change Wallpaper for Gnome Devices
- Change Wallpaper for non-Gnome Devices
- Set Timezone
- Set Time and Date
- Launch an App
Sending Commands
To begin sending commands, locate the device in Devices & Groups, check the box next to it, and then click Actions > ellipsis (...) > Run Script.
Then, paste the command in the window.
Use exit codes to track the progress of your commands in the Event Feed. For example, use “0” for successful commands and “1” for failures.
For repetitive actions, you can also bind a script to a button or other component. Learn more about creating a custom action.
Debian-based Commands
Install an App
#!/bin/bash
apt update
apt install -y myapp
if [ $? -eq 0 ]; then
echo "Installation successful"
else
echo "Installation failed"
fi
Uninstall an App
#!/bin/bash
package_name="myapp"
echo "Uninstalling $package_name..."
apt-get purge -y "$package_name"
if [ $? -eq 0 ]; then
echo "Successfully uninstalled $package_name"
else
echo "Failed to uninstall $package_name"
fi
Check the Status of a Service
#!/bin/bash
systemctl status myapp
Modify Files
#!/bin/bash
content="This is the new content to append to the file."
echo "$content" /path/to/your/file.txt
Remove File
#!/bin/bash
rm /path/to/file
CPU, Memory Usage
#!/bin/bash
cpu_info=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1}')
echo "CPU Usage: $cpu_info%"
memory_info=$(free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2}')
echo "$memory_info"
Reboot
#!/bin/bash
sudo reboot
Check Wi-Fi Settings
#!/bin/bash
if ! command -v nmcli &/dev/null; then
echo "NetworkManager is not installed. Please install NetworkManager."
exit 1
fi
if ! nmcli -t -f DEVICE,STATE connection show --active | grep -q "wifi"; then
echo "No active WiFi connection found."
exit 1
fi
wifi_info=$(nmcli -t -f SSID,DEVICE,BSSID,MODE,CHAN,FREQ,RATE,SIGNAL connection show --active | grep "wifi")
echo "WiFi Connection Information:"
echo "-----------------------------"
echo "$wifi_info"
Modify Wi-Fi Settings
#!/bin/bash
if ! command -v nmcli &/dev/null; then
echo "NetworkManager is not installed. Please install NetworkManager."
exit 1
fi
if [ $# -ne 2 ]; then
echo "Usage: $0 <ssid> <password>"
exit 1
fi
ssid="$1"
password="$2"
nmcli device wifi connect "$ssid" password "$password"
if [ $? -eq 0 ]; then
echo "Successfully connected to $ssid."
else
echo "Failed to connect to $ssid."
fi
Add Wi-Fi
#!/bin/bash
if ! command -v nmcli &/dev/null; then
echo "NetworkManager is not installed. Please install NetworkManager."
exit 1
fi
ssid="<ssid>"
password="<password>"
nmcli device wifi connect "$ssid" password "$password"
if [ $? -eq 0 ]; then
echo "Successfully connected to $ssid."
else
echo "Failed to connect to $ssid."
fi
Remove Wi-Fi
#!/bin/bash
if ! command -v nmcli &/dev/null; then
echo "NetworkManager is not installed. Please install NetworkManager."
exit 1
fi
ssid="ssid1"
connection_id=$(nmcli connection show | grep "$ssid" | awk '{print $1}')
if [ -z "$connection_id" ]; then
echo "WiFi connection '$ssid' not found."
exit 1
fi
echo "Removing WiFi connection: $ssid"
nmcli connection delete "$connection_id"
Lock Screen
#!/bin/bash
gnome-screensaver-command --lock
Turn Bluetooth On
#!/bin/bash
bluetoothctl power on
Turn Bluetooth Off
#!/bin/bash
bluetoothctl power off
Change Wallpaper for Gnome Devices
#!/bin/bash
gsettings set org.gnome.desktop.background picture-uri "file:///path/to/your/image.jpg"
Change Wallpaper for non-Gnome Devices
#!/bin/bash
feh --bg-scale /path/to/your/image.jpg
Set Timezone
#!/bin/bash
timedatectl set-timezone America/New_York
Set Time and Date
#!/bin/bash
timedatectl set-time "YYYY-MM-DD HH:MM:SS"
Launch an App
DISPLAY=:0 firefox https://esper.io
You may need to run the following command before running the DISPLAY=:0 command:
xhost +