Created
November 12, 2021 19:38
-
-
Save tralce/6ef858f3761884dc24d6b290295a4b10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script is heavily inspired by the getinfo.sh found | |
# on https://forums.centos.org/viewtopic.php?t=870 | |
# s3 code taken and rewritten from | |
# https://stackoverflow.com/questions/44751574/uploading-to-amazon-s3-via-curl-route/44751929 | |
counter=0 | |
IFS=$'\n' | |
fail() { | |
case $1 in | |
0) exit 0;; | |
1) echo "Failed to create temporary files.";; | |
2) echo -e "One or more of bucket, key, or secret not specified.\nNot attempting to upload to s3.\nTo upload to s3, invoke:\n$(basename $0) -b bucketname -k awsaccesskey -s awssecret";; | |
*) echo "Undocumented failure.";; | |
esac | |
exit 1 | |
} | |
while getopts "b:k:s:h" arg | |
do | |
case $arg in | |
b) bucket="$OPTARG";; | |
k) s3Key="$OPTARG";; | |
s) s3Secret="$OPTARG";; | |
h) echo -e "To upload to s3, invoke:\n$(basename $0) -b bucketname -k awsaccesskey -s awssecret";fail 0;; | |
esac | |
done | |
shift $(( OPTIND - 1 )) | |
txtfile="`mktemp -t $(basename $0).$(hostname).$(date +%Y-%m-%d).XXXXXX.txt`" || fail 1 | |
tarfile="`mktemp -t $(basename $0).$(hostname).$(date +%Y-%m-%d).XXXXXX.tar.gz`" || fail 1 | |
commands=( | |
'uname -rmi' | |
'cat /etc/redhat-release' | |
'yum repolist all' | |
'egrep "include|exclude" /etc/yum.repos.d/*.repo' | |
'cat /etc/yum.conf' | |
'ls /etc/yum.repos.d | xargs -i bash -c "echo {};cat /etc/yum.repos.d/{};echo;echo"' | |
'rpm -qa *-release*' | |
'rpm -qa kernel* | sort' | |
'rpm -qa yum* rpm-* python | sort' | |
'rpm -qa kmod* kmdl*' | |
'rpm -qa' | |
'hostname' | |
'ifconfig -a' | |
'brctl show' | |
'route -n' | |
'sysctl -a' | |
'ip rule show' | |
'ip route show' | |
'cat /etc/resolv.conf' | |
'egrep "net|hosts" /etc/nsswitch.conf' | |
'chkconfig --list | grep -Ei "network|wpa"' | |
'free -m' | |
'lspci -nn' | |
'lsusb' | |
'cat /etc/fstab' | |
'df -h' | |
'fdisk -lu' | |
'parted -l' | |
'blkid' | |
'cat /proc/mdstat' | |
'pvs' | |
'vgs' | |
'lvs' | |
'getenforce' | |
'sestatus' | |
'systemctl list-unit-files | grep enabled' | |
'systemctl | grep running' | |
'chkconfig' | |
'ps -ef' | |
) | |
echo -e "==========================================\nBeginning data collection.\nTotal commands to run: ${#commands[@]}\n==========================================\n\n" | tee -a $txtfile | |
for cmd in ${commands[@]} | |
do | |
echo -e "== BEGIN $cmd ==" >> $txtfile | |
if which ${cmd%%[[:space:]]*} &> /dev/null | |
then | |
if eval $cmd >> $txtfile | |
then | |
((counter=counter+1)) | |
fi | |
else | |
echo "System doesn't seem to have ${cmd%%[[:space:]]*} in \$PATH" >> $txtfile | |
fi | |
echo -e "== END $cmd ==\n\n" >> $txtfile | |
done | |
if [ $UID -eq 0 ] | |
then | |
tar czf $tarfile /etc/ | |
else | |
echo "Not root, can't tar /etc/" | |
fi | |
echo -e "==========================================\nCompleted data collection.\nTotal commands run: ${counter}\nTest file length: $(cat $txtfile|wc -l) lines\nText file: ${txtfile}\nTarball: ${tarfile}\n==========================================\n\n" | tee -a $txtfile | |
upload_to_s3() { | |
file=$(basename $1) | |
dir=$(dirname $1) | |
cd $dir | |
contentType="$(file -b --mime-type $file)" | |
resource="/${bucket}/${file}" | |
dateValue=`date -R` | |
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}" | |
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64` | |
echo -e "==========================================\nAttempting to upload $file to s3.\nNo output is good.\n==========================================\n" | |
curl -X PUT -T "${file}" -H "Host: ${bucket}.s3.amazonaws.com" -H "Date: ${dateValue}" -H "Content-Type: ${contentType}" -H "Authorization: AWS ${s3Key}:${signature}" https://${bucket}.s3.amazonaws.com/${file} | |
} | |
if [ -n "$bucket" -a -n "$s3Key" -a -n "$s3Secret" ] | |
then | |
upload_to_s3 $txtfile | |
upload_to_s3 $tarfile | |
else | |
fail 2 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment