Compare commits

..

11 commits

Author SHA1 Message Date
71ee8a4ba4 Fixing some data that was left in 2024-01-26 17:39:04 -06:00
8ab998e252 Config support for band.bash 2023-12-17 22:29:33 -06:00
6d893a43a6 Copied code from the bash framework and add json based config file support 2023-12-09 22:37:59 -06:00
kake26
3ccf356c11 vnstat fix
Configured vnstat to save DB to external USB.

Per

https://openwrt.org/docs/guide-user/services/network_monitoring/vnstat

This was to solve the persistence issue. Now vnstat db should be backed up normally.
2022-12-26 22:40:13 -06:00
kake26
feff8400ff Ntfy support
Added ntfy support
2022-12-17 00:15:03 -06:00
kake26
d39f56dafc ntfy support
Added ntfy support
2022-12-17 00:13:34 -06:00
kake26
1417d71d7c band.bash added
Bandwidth usage reporting tool.
2021-09-25 23:58:04 +02:00
kake26
1d6056b61d Added backup.bash
Added backup.bash from my OpenWrt scripts.
2021-09-25 23:56:05 +02:00
kake26
ed880365cb Update 'README.md'
updated readme
2021-09-25 23:44:35 +02:00
kake26
d3d237030d Update 'README.md'
Updated wrong branch fixing
2021-09-25 23:42:02 +02:00
kake26
0908ee4559 Update 'README.md'
Created some branches for various types and updated the readme.
2021-09-25 23:41:09 +02:00
5 changed files with 135 additions and 12 deletions

View file

@ -1,15 +1,5 @@
# Bash-Stash # Bash-Stash
A collection of console based bash scripts I've written at various times. It may include scripts written in other languages. To check out this repo you must select a branch you can do this via the following command .
git clone -b branch URL
# Console
These are daily use type console scripts.
# OpenWrt # OpenWrt
These are designed to be used with OpenWrt for various tasks. These are scripts I've used on OpenWrt for various purposes.
Please see the read me in each branch for more info.

33
backup.bash Normal file
View file

@ -0,0 +1,33 @@
#!/bin/bash
set -eo pipefail # you cann add u into -eo, but it drives me nuts so I won't
if [[ -n "${BASHD_DEBUG}" ]]; then # a inevitability that this will be used
set -x
fi
trap cleanup EXIT # A little more robust cleanup
cleanup() {
# We can clean up any temp files or what nots, but for now a place holder
true
}
source ./config.bash
# Run backups via restic
bkpwd=$(read_json "$JSON_FILE" "restic" "password")
export RESTIC_PASSWORD="$bkpwd"
# Stuff to backup
/usb/scripts/bin/restic -r sftp:nbak@192.168.1.168:/storage/backup/openwrt backup /etc
curl -d "ETC backed up" 192.168.1.168:83/openwrt_backup
/usb/scripts/bin/restic -r sftp:nbak@192.168.1.168:/storage/backup/openwrt backup /usb/scripts
curl -d "Scripts backed up" 192.168.1.168:83/openwrt_backup
/usb/scripts/bin/restic -r sftp:nbak@192.168.1.168:/storage/backup/openwrt backup /root
curl -d "Root backed up" 192.168.1.168:83/openwrt_backup
/usb/scripts/bin/restic -r sftp:nbak@192.168.1.168:/storage/backup/openwrt backup /usb/vnstat/vnstat.db
curl -d "Vnstat backed up" 192.168.1.168:83/openwrt_backup

35
band.bash Normal file
View file

@ -0,0 +1,35 @@
#!/bin/bash
# Requires vnstat to be running on target system
set -eo pipefail # you cann add u into -eo, but it drives me nuts so I won't
if [[ -n "${BASHD_DEBUG}" ]]; then # a inevitability that this will be used
set -x
fi
trap cleanup EXIT # A little more robust cleanup
cleanup() {
# We can clean up any temp files or what nots, but for now a place holder
true
}
source ./config.bash
# initial values
mtotal=1000 # monthly total in GB for high end cut off
dmax=40 # daily max usage value
md=`date +%d` # day of the month numerically
cmd=$(($dmax * $md)) # computed max daily
wif="wan"
token=$(read_json "$JSON_FILE" "ntfy" "token")
# now vnstat stuff, some of this is specific to openwrt
vnhourly=`vnstat -i $wif -d -s --oneline | awk -F\; '{print $6}'` # total monthly usage
vnmonthly=`vnstat -i $wif -d -s --oneline | awk -F\; '{print $11}'` # daily total usage
logger "dom $md cm $cmd vnhourly $vnhourly vnmonthly $vnmonthly";
curl -d "dom $md cm $cmd vnhourly $vnhourly vnmonthly $vnmonthly" 192.168.1.168:83/bandmon
curl -H "Authorization: Bearer $token" -d "dom $md cm $cmd vnhourly $vnhourly vnmonthly $vnmonthly" https://pngpst.net/openwrt_lan

20
commando.bash Normal file
View file

@ -0,0 +1,20 @@
#!/bin/bash
# commando.bash
set -eo pipefail # you cann add u into -eo, but it drives me nuts so I won't
if [[ -n "${BASHD_DEBUG}" ]]; then # aievitability that this will be used
set -x
fi
trap cleanup EXIT # A little more robust cleanup
cleanup() {
# We can clean up any temp files or what nots, but for now a place holder
true
}
source ./config.bash
token=$(read_json "$JSON_FILE" "ntfy" "token")

45
config.bash Normal file
View file

@ -0,0 +1,45 @@
#!/bin/bash
JSON_FILE="config.json"
read_json() {
local JSON_FILE="$1"
local SECTION="$2"
local KEY="$3"
jq -r ".${SECTION}.${KEY}" "$JSON_FILE"
}
# Function to write a value to a JSON configuration file
write_json() {
local JSON_FILE="$1"
local SECTION="$2"
local KEY="$3"
local VALUE="$4"
# It important to check if the file is valid otherwise stuff breaks
if ! jq -e . < "$JSON_FILE" > /dev/null 2>&1; then
echo "Error: JSON file is not valid JSON."
return 1
fi
# Using jq to set the value. The original file is replaced with a new file with the updated value.
jq ".${SECTION}.${KEY} = \"$VALUE\"" "$JSON_FILE" > "temp.json" && mv "temp.json" "$JSON_FILE"
}
create_json() {
local JSON_FILE="$1"
echo '{"bashini": "new"}' | jq '.' > "$JSON_FILE" # well we need something in there
}
check_json() {
local JSON_FILE="$1"
if [ ! -f "$JSON_FILE" ]; then
create_json "$JSON_FILE"
fi
}
check_json "$JSON_FILE"