FIX: Add error handling to remaining piped command assignments
Fixed 5 additional piped command assignments that could produce empty values if any command in the pipeline fails with set -eo pipefail: - Line 134: all_domains from grep | cut | tr - Added || echo "" - Line 402: db_prefix from sed | cut - Added || echo "" - Line 689: home_dir from grep | cut - Added || echo "" - Line 729: primary_domain from grep | cut - Added || echo "" - Line 730: home_dir from grep | cut - Added || echo "" - Line 731: disk_used from grep | cut - Added || echo "0" These changes ensure consistent error handling for all piped commands with set -eo pipefail enabled, preventing silent failures and data loss.
This commit is contained in:
+6
-6
@@ -131,7 +131,7 @@ get_cpanel_user_info() {
|
|||||||
local home_dir="/home/${username}"
|
local home_dir="/home/${username}"
|
||||||
|
|
||||||
# Get addon/parked domains
|
# Get addon/parked domains
|
||||||
local all_domains=$(grep "^DNS" -- "$user_file" | cut -d= -f2 | tr '\n' ' ')
|
local all_domains=$(grep "^DNS" -- "$user_file" | cut -d= -f2 | tr '\n' ' ' || echo "")
|
||||||
|
|
||||||
# Get disk usage
|
# Get disk usage
|
||||||
local disk_used=$(du -sh "$home_dir" 2>/dev/null | awk '{print $1}' || echo "0B")
|
local disk_used=$(du -sh "$home_dir" 2>/dev/null | awk '{print $1}' || echo "0B")
|
||||||
@@ -399,7 +399,7 @@ get_interworx_user_databases() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Get first 8 characters of domain (removing dots) as database prefix
|
# Get first 8 characters of domain (removing dots) as database prefix
|
||||||
local db_prefix=$(echo "$primary_domain" | sed 's/\.//g' | cut -c1-8)
|
local db_prefix=$(echo "$primary_domain" | sed 's/\.//g' | cut -c1-8 || echo "")
|
||||||
|
|
||||||
# Query MySQL for databases with this prefix
|
# Query MySQL for databases with this prefix
|
||||||
mysql -e "SHOW DATABASES" 2>/dev/null | grep "^${db_prefix}_" || true
|
mysql -e "SHOW DATABASES" 2>/dev/null | grep "^${db_prefix}_" || true
|
||||||
@@ -686,7 +686,7 @@ get_database_domain() {
|
|||||||
|
|
||||||
find_user_wordpress_sites() {
|
find_user_wordpress_sites() {
|
||||||
local username="$1"
|
local username="$1"
|
||||||
local home_dir=$(get_user_info "$username" | grep "^HOME_DIR=" | cut -d= -f2)
|
local home_dir=$(get_user_info "$username" | grep "^HOME_DIR=" | cut -d= -f2 || echo "")
|
||||||
|
|
||||||
if [ -z "$home_dir" ] || [ ! -d "$home_dir" ]; then
|
if [ -z "$home_dir" ] || [ ! -d "$home_dir" ]; then
|
||||||
return 1
|
return 1
|
||||||
@@ -726,9 +726,9 @@ show_user_summary() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Parse info
|
# Parse info
|
||||||
local primary_domain=$(echo "$user_info" | grep "^PRIMARY_DOMAIN=" | cut -d= -f2)
|
local primary_domain=$(echo "$user_info" | grep "^PRIMARY_DOMAIN=" | cut -d= -f2 || echo "")
|
||||||
local home_dir=$(echo "$user_info" | grep "^HOME_DIR=" | cut -d= -f2)
|
local home_dir=$(echo "$user_info" | grep "^HOME_DIR=" | cut -d= -f2 || echo "")
|
||||||
local disk_used=$(echo "$user_info" | grep "^DISK_USED=" | cut -d= -f2)
|
local disk_used=$(echo "$user_info" | grep "^DISK_USED=" | cut -d= -f2 || echo "0")
|
||||||
|
|
||||||
# Display
|
# Display
|
||||||
echo " Username: $username"
|
echo " Username: $username"
|
||||||
|
|||||||
Reference in New Issue
Block a user