save point
This commit is contained in:
parent
ba08698042
commit
7c113360c8
2 changed files with 80 additions and 7 deletions
68
script.bash
Normal file → Executable file
68
script.bash
Normal file → Executable file
|
@ -18,9 +18,75 @@ cleanup() {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
source ./config_json.bash # can be json or ini, I preffer json
|
source ./config_json.bash # can be json or ini, I preffer json
|
||||||
|
|
||||||
|
# Keydb / Redis interaction functions, works for both
|
||||||
|
|
||||||
|
dbcmd="keydb-cli"
|
||||||
|
|
||||||
|
# Check if keydb-cli is installed
|
||||||
|
check_redis_cli() {
|
||||||
|
if ! command -v $dbcmd &> /dev/null; then
|
||||||
|
echo "Error: $dbcmd is not installed. Please install keydb package."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Save data to Redis
|
||||||
|
# Usage: redis_save key value
|
||||||
|
redis_save() {
|
||||||
|
local key="$1"
|
||||||
|
local value="$2"
|
||||||
|
|
||||||
|
if [[ -z "$key" || -z "$value" ]]; then
|
||||||
|
echo "Error: Both key and value are required"
|
||||||
|
echo "Usage: redis_save key value"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $dbcmd SET "$key" "$value"; then
|
||||||
|
echo "Successfully saved '$value' with key '$key'"
|
||||||
|
else
|
||||||
|
echo "Failed to save data to Redis"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Retrieve data from Redis
|
||||||
|
# Usage: redis_get key
|
||||||
|
redis_get() {
|
||||||
|
local key="$1"
|
||||||
|
|
||||||
|
if [[ -z "$key" ]]; then
|
||||||
|
echo "Error: Key is required"
|
||||||
|
echo "Usage: redis_get key"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local value
|
||||||
|
value=$($dbcmd GET "$key")
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
if [[ -z "$value" ]]; then
|
||||||
|
echo "No value found for key '$key'"
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
echo "$value"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Failed to retrieve data from Redis"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Example usage
|
||||||
|
check_redis_cli
|
||||||
|
|
||||||
|
# Uncomment these lines to test the functions
|
||||||
|
# redis_save "mykey" "Hello from Bash!"
|
||||||
|
# redis_get "mykey"
|
||||||
|
|
||||||
# Code goes here
|
# Code goes here
|
||||||
|
|
||||||
|
redis_save "bashini" "new"
|
||||||
|
redis_get "bashini"
|
||||||
|
|
||||||
|
|
19
sys.bash
19
sys.bash
|
@ -17,23 +17,30 @@ function meminfo() {
|
||||||
echo "Memory:"
|
echo "Memory:"
|
||||||
# We will get to this later
|
# We will get to this later
|
||||||
#total=$(free -h| grep ) #| grep -E "Mem|Swap"
|
#total=$(free -h| grep ) #| grep -E "Mem|Swap"
|
||||||
|
total=$(free -h | awk '/^Mem/ {print $2}')
|
||||||
|
used=$(free -h | awk '/^Mem/ {print $3}')
|
||||||
|
free=$(free -h | awk '/^Mem/ {print $4}')
|
||||||
|
echo "Total: $total, Used: $used, Free: $free"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function diskinfo() {
|
function diskinfo() {
|
||||||
echo "Disk:"
|
echo "Disk:"
|
||||||
# We will get to this later
|
# We will get to this later
|
||||||
|
disks=$(lsblk -d -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL | awk 'NR>1 {print $1,$2,$3,$4,$5}')
|
||||||
|
for disk in $disks; do
|
||||||
|
echo "$disk"
|
||||||
|
done
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function networkinfo() {
|
function networkinfo() {
|
||||||
echo "Network:"
|
echo "Network:"
|
||||||
# get network interfaces and usage
|
# get network interfaces and usage
|
||||||
|
|
||||||
# get network adapters and usage
|
net=$(ifstat -j | jq -r '.[] | "\(.interface) TX:\(.tx.kbps) RX:\(.rx.kbps)"')
|
||||||
adapters=$(ip -s addr | grep -E '^[0-9]:' | awk -F ':' '{print $2}')
|
for interface in $net; do
|
||||||
for adapter in $adapters; do
|
echo "$interface"
|
||||||
rx=$(ip -s link show $adapter | awk '/RX:/ {print $2}')
|
|
||||||
tx=$(ip -s link show $adapter | awk '/TX:/ {print $2}')
|
|
||||||
echo -e "$adapter\tRX: $rx\tTX: $tx"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue