Improve script

This commit is contained in:
Loïc Guégan 2024-07-07 08:50:14 +02:00
parent a93e496b52
commit e56009e7a8
2 changed files with 28 additions and 7 deletions

View file

@ -24,7 +24,7 @@ Important note: Depending on the system, some entries may not be available.
| ping | Check if ping succeed (internet is available) |
| boot_folder | Recursive listing of /boot/ |
| root_folder | Content of / |
| home_folder | Content of $HOME |
| home_\<path\> | List the content of each home directory (at the root only) |
| cmd_\<command\>_version | Get the version of some specific commands (e.g: gcc, python etc) |
| /proc/cmdline | See kernel parameters |
| kernel_config | Get kernel config |

View file

@ -79,15 +79,30 @@ sysdump() {
echo "Current working directory is ${PWD}" >> "${LOG_FILE}"
echo "Current user is $(whoami)" >> "${LOG_FILE}"
echo "${DUMP_DELIMITER}"
# Populate users path
USER_DIRS=()
if [ $(id -u) -eq 0 ]
then
for dir in /home/*
do
[[ ${dir} != *"lost+found"* ]] && USER_DIRS+=($dir)
done
USER_DIRS+=(/root)
else
USER_DIRS+=($HOME)
fi
# Start dump
echo "{"
USE_COMMA=1
# safecat
dump "/etc/nftables.conf" safecat /etc/nftables.conf
dump "/etc/group" safecat /etc/group
dump "$HOME/.bashrc" safecat $HOME/.bashrc
dump "$HOME/.bash_profile" safecat $HOME/.bash_profile
dump "$HOME/.bash_history" safecat $HOME/.bash_history
for hp in "${USER_DIRS[@]}"
do
dump "${hp}/.bashrc" safecat ${hp}/.bashrc
dump "${hp}/.bash_profile" safecat ${hp}/.bash_profile
dump "${hp}/.bash_history" safecat ${hp}/.bash_history
done
dump "/etc/fstab" safecat /etc/fstab
dump "/etc/ssh/sshd_config" safecat /etc/ssh/sshd_config
dump "/proc/cpuinfo" safecat /proc/cpuinfo
@ -119,7 +134,10 @@ sysdump() {
dump "free" safecmd free -h
dump "df" safecmd df -h
dump "boot_folder" safecmd ls -R /boot/
dump "home_folder" safecmd ls -al ${HOME}
for hp in "${USER_DIRS[@]}"
do
dump "home_${hp}" safecmd ls -al ${hp}
done
dump "root_folder" safecmd ls -al /
dump "uid" safecmd id -u
dump "gid" safecmd id -g
@ -158,8 +176,11 @@ sysdump() {
dump "fdisk" safecmdroot fdisk -l
dump "dmesg" safecmdroot dmesg
# dumpdisk
[ -d "${HOME}/.ssh" ] && dumpdisk "tar_${HOME}/.ssh" "${HOME}/.ssh"
[ -d "${HOME}/.gnupg" ] && dumpdisk "tar_${HOME}/.gnupg" "${HOME}/.gnupg"
for hp in "${USER_DIRS[@]}"
do
[ -d "${hp}/.ssh" ] && dumpdisk "tar_${hp}/.ssh" "${hp}/.ssh"
[ -d "${hp}/.gnupg" ] && dumpdisk "tar_${hp}/.gnupg" "${hp}/.gnupg"
done
USE_COMMA=0
dump "dump_log" cat "${LOG_FILE}"
echo "}"