Created
December 12, 2016 14:27
-
-
Save rytoj/c851abb5f8929870cb1c6ad13e4d5a27 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# Program to output a system information page | |
TITLE="System Information Report for $HOSTNAME" | |
TIME=$(date +%F:%T) | |
TIMESTAMP="Generated $TIME, by $USER uid: $(id -u)" | |
TOTALSPACE=$(df -h) | |
SELIUX_STATE=$(sestatus | head -1 ; sestatus | grep --color=auto "Current mode";) | |
LARGEST_FILES=$(du -a /home 2>/dev/null | sort -n -r | head -n 10) | |
type systemd 2>/dev/null && SERVICES=$(systemctl -t service) || SERVICES=$(chkconfig --list) #for cebos6.8 | |
OLD_IFS=$IFS #old IFS bakcup | |
usage() { | |
echo "usage: $(basename $0) [OPTION]... [FILE]" | |
echo "-o, --output [file] generate html file" | |
return | |
} | |
# #Checks if root | |
# if [ $(id -u) -eq 0 ]; then | |
# echo "You are root">&2 | |
# else | |
# echo "You are user with uid: $(id -u)">&2 | |
# fi | |
report_uptime() { | |
# func prints system uptime | |
echo "<H3> System Uptime</H3> | |
<PRE>$(uptime)</PRE>" | |
return | |
} | |
report_selinux() { | |
# func selinux state | |
echo "<H3> SeLinux info</H3> | |
<PRE>$SELIUX_STATE</PRE>" | |
return | |
} | |
report_services() { | |
# list services | |
echo "<H3> Services info:</H3> | |
<PRE>$SERVICES</PRE>" | |
return | |
} | |
report_freespace(){ | |
# func print disk usage | |
echo "<H3>Disk Usage</H3> | |
<PRE> | |
$TOTALSPACE | |
</PRE>" | |
return | |
} | |
report_largests_files(){ | |
# func print disk usage | |
echo "<H3>10 Largest's files</H3> | |
<PRE> | |
$LARGEST_FILES | |
</PRE>" | |
return | |
} | |
user_info(){ | |
# func prints user information prom /etc/passw | |
passw_info=$(grep $(whoami) /etc/passwd) | |
if [ -n $passw_info ]; then | |
IFS=: | |
read user pw uid gid name home shell <<< "$passw_info" | |
cat << _EOF_ | |
<H3>User Info</H3> | |
<PRE> | |
<b>User</b>= $user | |
<b>UID</b>= $uid | |
<b>Home</b>= $home | |
<b>Shell</b>= $shell | |
</PRE> | |
_EOF_ | |
else | |
echo "No such user">&2 | |
exit 1 | |
fi | |
reset_IFS | |
} | |
reset_IFS(){ | |
IFS=$OLD_IFS | |
} | |
generate_main_html(){ | |
# func prints main html page | |
cat << _EOF_ | |
<HTML> | |
<HEAD> | |
<TITLE>$TITLE</TITLE> | |
</HEAD> | |
<BODY> | |
<H1>$TITLE</H1> | |
$(user_info) | |
$(report_services) | |
$(report_selinux) | |
$(report_freespace) | |
$(report_largests_files) | |
$(report_uptime) | |
<P><i>$TIMESTAMP</i></P> | |
</BODY> | |
</HTML> | |
_EOF_ | |
} | |
if [ -n $1 ]; then | |
case $1 in | |
-h|--help) | |
usage | |
;; | |
-o|--output) | |
if [ -e $2 ]; then # If file exists | |
echo "file: $2 already exists" | |
exit 1 | |
fi | |
generate_main_html > $2 | |
if [ $? -ne 0 ]; then | |
echo "Error, something went wrong">&2 | |
exit 1 | |
else | |
echo "$2 succesfully generated" | |
fi | |
;; | |
pattern ) | |
;; | |
pattern ) | |
;; | |
*) | |
echo "Invalid parameter">&2 | |
usage>&2 | |
exit 1 | |
;; | |
esac | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment