Skip to content

Instantly share code, notes, and snippets.

@moutons

moutons/hab-gatherlogs.sh Secret

Last active Apr 11, 2020
Embed
What would you like to do?
a potentially functional habitat gather-logs script for getting support from Chef
#!/usr/bin/env bash
# a potentially functional habitat gather-logs script for getting support from Chef
# authors: Chef's Support team
# source: https://gist.github.com/moutons/5958de5c9bde95d69de44047794b6059
set -o errexit
set -o pipefail
export HAB_LICENSE=accept
readonly NOW_ISH=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
readonly HOSTNAMEF=$(hostname -f)
readonly TARNAME="${HOSTNAMEF}-${NOW_ISH}"
declare -a INCLUDES=("/hab/user/*/config" "/hab/svc/*/config" "/hab/svc/*/logs" "/proc/cpuinfo" "/proc/meminfo" "/proc/version" "/proc/sys/crypto/fips_enabled" "/etc/resolv.conf" "/etc/hosts" "/etc/*-release" "/var/log/syslog" "/var/log/messages")
mkdir /tmp/gatherlogs-${NOW_ISH}
hab --version > /tmp/gatherlogs-${NOW_ISH}/hab_version.txt
hab sup status > /tmp/gatherlogs-${NOW_ISH}/hab_sup_version.txt
hab pkg list --all > /tmp/gatherlogs-${NOW_ISH}/hab_pkg_list.txt
df --human-readable > /tmp/gatherlogs-${NOW_ISH}/df_h.txt
df --inodes > /tmp/gatherlogs-${NOW_ISH}/df_i.txt
df --block-size=1K > /tmp/gatherlogs-${NOW_ISH}/df_k.txt
free -m > /tmp/gatherlogs-${NOW_ISH}/free_m.txt
ps fauxww > /tmp/gatherlogs-${NOW_ISH}/ps_fauxww.txt
umask > /tmp/gatherlogs-${NOW_ISH}/umask.txt
uname -a > /tmp/gatherlogs-${NOW_ISH}/uname_a.txt
sysctl -a > /tmp/gatherlogs-${NOW_ISH}/sysctl_a.txt 2>/dev/null
dmesg --ctime > /tmp/gatherlogs-${NOW_ISH}/dmesg.txt
su -m hab -c "ulimit -a" > /tmp/gatherlogs-${NOW_ISH}/ulimit_a_hab.txt
find /hab/pkgs -maxdepth 4 -mindepth 4 -type d -ls > /tmp/gatherlogs-${NOW_ISH}/find_hab_pkgs.txt
hostname --fqdn > /tmp/gatherlogs-${NOW_ISH}/hostname_--fqdn.txt
dig ${HOSTNAMEF} > /tmp/gatherlogs-${NOW_ISH}/dig-fqdn.txt
ip addr show > /tmp/gatherlogs-${NOW_ISH}/ip_addr_show.txt
ping -c 2 $(hostname) > /tmp/gatherlogs-${NOW_ISH}/ping_-c_2_hostname.txt
ping -c 2 ${HOSTNAMEF} > /tmp/gatherlogs-${NOW_ISH}/ping_-c_2_fqdn.txt
ss -ontap > /tmp/gatherlogs-${NOW_ISH}/ss.txt
journalctl --since "2 days ago" > /tmp/gatherlogs-${NOW_ISH}/journalctl_--since_2_days_ago.txt
for include in "${INCLUDES[@]}"
do
rsync --ignore-missing-args --copy-links --relative --recursive $include "/tmp/gatherlogs-${NOW_ISH}/"
done
tar -czf "./${TARNAME}.tar.gz" "/tmp/gatherlogs-${NOW_ISH}/" 2>/dev/null
echo "Please send $(hostname)-${NOW_ISH}.tar.gz to the Chef Support team!"
@clavery-chef

This comment has been minimized.

Copy link

@clavery-chef clavery-chef commented Apr 1, 2020

go on and add an:

export HAB_LICENSE=accept

to the top line in case the customers broken/not set that part :)

@moutons

This comment has been minimized.

Copy link
Owner Author

@moutons moutons commented Apr 11, 2020

🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.