Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created November 9, 2017 17:21
Show Gist options
  • Save tripflex/82e3a7b91eacc0cc62866531083fb8ad to your computer and use it in GitHub Desktop.
Save tripflex/82e3a7b91eacc0cc62866531083fb8ad to your computer and use it in GitHub Desktop.
CloudLinux Doctor Bash File
#!/bin/bash
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
DEST=/root/cl-report
UPLOAD_URL=https://doctor.cloudlinux.com/doctor/upload
CAT=`command -v cat`
UNAME=`command -v uname`
CP="Unknown"
SERVER_ID=
cleanup() {
rm -f $DEST $DEST.wget
}
test_curl() {
command -v curl 2>&1 >/dev/null
return $?
}
test_wget() {
command -v wget 2>&1 >/dev/null
if [ 0 -eq $? ]; then
if [ -x `command -v wget` ]; then
return 0
fi
fi
return 1
}
curl_upload() {
curl -s -H "serverid: $SERVER_ID" -F reportfile=@"$DEST" $UPLOAD_URL
}
wget_upload() {
echo -e "--FILEUPLOAD\r\n" > $DEST.wget
echo -e "--FILEUPLOAD\r\n" > $DEST.wget
echo -e "Content-Disposition: form-data; name=\"reportfile\"; filename=\"$DEST\"\r\n" >> $DEST.wget
echo -e "Content-Type: application/octet-stream\r\n" >> $DEST.wget
echo -e "Media Type: application/octet-stream\r\n\r\n" >> $DEST.wget
cat $DEST >> $DEST.wget
echo -e "--FILEUPLOAD--\r\n" >> $DEST.wget
wget -O - -qq -t 1 --header="serverid: $SERVER_ID" --header="Content-type: multipart/form-data; boundary=FILEUPLOAD" --post-file $DEST.wget $UPLOAD_URL
}
upload() {
if test_curl
then
curl_upload
else
wget_upload
fi
echo
}
mecho(){
echo $1 >> $DEST
}
start(){
if ! test_wget; then
if ! test_curl; then
echo "Cannot find wget or curl"
fi
#echo "Using curl"
fi
echo "------ CL INFO ---" > $DEST
}
sep(){
echo "------ $1 ---" >> $DEST
}
run(){
sep "$1"
sh -c "$1" >> $DEST 2>&1
}
dump() {
sep "cat $1"
$CAT $1 >> $DEST 2>&1
}
get_server_id() {
if [ -f /etc/sysconfig/rhn/systemid ]; then
SERVER_ID=`grep '<value><string>ID-' /etc/sysconfig/rhn/systemid |sed -n 's:.*<string>ID-\(.*\)</string>.*:\1:p'`
else
SERVER_ID='NA'
fi
sep "SERVER ID"
mecho "serverid: $SERVER_ID"
}
detect_cp() {
CP_VERSION="Unknown"
SOFTACULOUS=0
if [ -d "/usr/local/psa/admin/" ]; then
CP="Plesk"
CP_VERSION=`cat /usr/local/psa/version`
if [ -e "/usr/local/softaculous" ]; then SOFTACULOUS=1; fi
fi
if [ -d "/usr/local/cpanel/whostmgr/docroot/" ]; then
CP="cPanel"
CP_VERSION=`/usr/local/cpanel/cpanel -V`
if [ -e "/usr/local/cpanel/whostmgr/cgi/softaculous" ]; then SOFTACULOUS=1; fi
fi
if [ -d "/usr/local/interworx/" ]; then
CP="InterWorx"
CP_VERSION=`cat /usr/local/interworx/iworx.ini|grep version`
if [ -e "/usr/local/softaculous" ]; then SOFTACULOUS=1; fi
fi
if [ -d "/usr/local/ispmgr/" ]; then
CP="ISPmanager"
CP_VERSION=`/usr/local/ispmgr/bin/ispmgr -v`
if [ -e "/usr/local/softaculous" ]; then SOFTACULOUS=1; fi
fi
if [ -d "/usr/local/directadmin/plugins/" ]; then
CP="DirectAdmin"
CP_VERSION=`/usr/local/directadmin/custombuild/build versions|sed -n 2p|cut -d":" -f2`
if [ -e "/usr/local/directadmin/plugins/softaculous" ]; then SOFTACULOUS=1; fi
fi
if [ -d "/usr/local/hostingcontroller/" ]; then
CP="Hosting Controller"
if [ -e "/usr/local/softaculous" ]; then SOFTACULOUS=1; fi
fi
if [ -d "/hsphere/shared" ]; then
CP="H-Sphere"
fi
sep "Control Panel"
mecho "CP: $CP"
mecho "VERSION: $CP_VERSION"
mecho "SOFTACULOUS: $SOFTACULOUS"
}
apache_info() {
sep "Apache Info"
if [ $CP == "cPanel" ]; then
/usr/sbin/httpd -V >> $DEST 2>&1
elif [ $CP == 'H-Sphere' ]; then
ps ax | grep httpd | grep hsphere | grep -v cpanel | head -1 | awk '{ print $5" -V"}' | sh >> $DEST 2>&1
else
apachectl -V >> $DEST 2>&1
fi
}
apache_modules() {
sep "Apache Modules"
if [ $CP == "cPanel" ]; then
/usr/sbin/httpd -M >> $DEST 2>&1
elif [ $CP == 'H-Sphere' ]; then
ps ax | grep httpd | grep hsphere | grep -v cpanel | head -1 | awk '{ print $5" -M"}' | sh >> $DEST 2>&1
else
apachectl -M >> $DEST 2>&1
fi
}
apache_status() {
sep "Apache Status"
if [ $CP == "cPanel" ]; then
/usr/sbin/httpd status >> $DEST 2>&1
elif [ $CP == 'H-Sphere' ]; then
ps ax | grep httpd | grep hsphere | grep -v cpanel | head -1 | awk '{ print $5" status"}' | sh >> $DEST 2>&1
else
apachectl status >> $DEST 2>&1
fi
}
apache_fullstatus() {
sep "Apache Full Status"
if [ $CP == "cPanel" ]; then
/usr/sbin/httpd fullstatus >> $DEST 2>&1
elif [ $CP == 'H-Sphere' ]; then
ps ax | grep httpd | grep hsphere | grep -v cpanel | head -1 | awk '{ print $5" fullstatus"}' | sh >> $DEST 2>&1
else
apachectl fullstatus >> $DEST 2>&1
fi
}
cPanel_forkbomb() {
if [ $CP == 'cPanel' ]; then
sep "cPanel Fork Bomb Protectoin"
grep "#cPanel Added Limit Protections" /etc/bashrc >> $DEST 2>/dev/null
grep "#cPanel Added Limit Protections" /etc/profile >> $DEST 2>/dev/null
if [ -e /etc/profile.d/limits.sh ]; then
echo /etc/profile.d/limits.sh exists >> $DEST
fi
if [ -e /etc/profile.d/limits.csh ]; then
echo /etc/profile.d/limits.csh exists >> $DEST
fi
fi
}
get_main_ip() {
sep "Main IP"
if test_curl
then
curl -4 -s -L http://cloudlinux.com/showip.php >>$DEST 2>&1
else
wget -qq --inet4-only -O - http://cloudlinux.com/showip.php >>$DEST 2>&1
fi
echo >>$DEST
}
litespeed_arch() {
sep "LiteSpeed Arch"
file `readlink -f /usr/local/lsws/bin/lshttpd` >> $DEST 2>&1
}
start
echo -n "Generating report..."
get_server_id
run "date"
run "$CAT /proc/cpuinfo"
run "$UNAME -a"
run "$UNAME -r"
run "$UNAME -m"
run "$UNAME -p"
run "$UNAME -o"
dump "/etc/redhat-release"
run 'rpm -q -a --queryformat="%{N}|%{V}-%{R}|%{arch}\n"'
dump "/etc/sysconfig/kernel"
dump "/proc/uptime"
dump "/proc/loadavg"
dump "/proc/vmstat"
dump "/proc/devices"
dump "/proc/diskstats"
dump "/proc/cmdline"
dump "/proc/mdstat"
dump "/proc/meminfo"
dump "/proc/swaps"
dump "/proc/filesystems"
dump "/proc/mounts"
dump "/proc/self/mountinfo"
dump "/proc/interrupts"
dump "/boot/grub/grub.conf"
run "grep DEFAULT /etc/default/grub"
run "grep vmlinuz /boot/grub2/grub.cfg| sed 's/root=.*//'"
dump "/boot/grub2/grub.cfg"
dump "/proc/zoneinfo"
run "ls -la /etc/grub.conf /boot/grub/grub.conf /boot/grub/menu.lst"
run "ls -l /boot"
run "ls -l /var/lve/"
run "export"
dump "/etc/sysconfig/i18n"
litespeed_arch
run "lvectl list"
run "lvectl list-user"
run "lveinfo -d --period=1d --by-fault=any"
run "php -i"
run "lspci"
run "ps auxwH"
dump "/sys/block/[xsh]*d*/queue/scheduler"
run "echo /sys/block/[shx]*d*"
run "mount"
dump "/etc/fstab"
run "iostat"
run "vmstat 1 3"
run "ifconfig|grep 'inet addr'|wc -l"
run "netstat -n"
run "top -b -n1"
run "iotop -b -n1"
run "df -h"
run "df -i"
run "echo /etc/yum.repos.d/*"
run "grep Port /etc/ssh/sshd_config"
dump "/etc/yum.conf"
run "yum repolist"
run "grep -n enabled /etc/yum/pluginconf.d/*"
dump "/proc/lve/list"
dump "/proc/user_beancounters"
run "dmidecode"
run "virt-what"
run "ipcs -m|sed -e s/-/=/g"
run "strings /opt/suphp/sbin/suphp|grep lve"
run "strings /usr/local/apache/bin/suexec|grep lve"
run "strings /usr/sbin/suexec|grep lve"
run "/usr/local/cpanel/bin/rebuild_phpconf --current"
run "cagefsctl --display-user-mode"
run "cagefsctl --cagefs-status"
run "cagefsctl --sanity-check"
run "cat /etc/cagefs/cagefs.mp"
run "grep pam_lve /etc/pam.d/*"
run "mysql -V"
run "lsmod"
run "locale"
run "grep -i rlimit /etc/httpd/conf/*.conf /etc/httpd/conf/*/*.conf /etc/httpd/conf.d/*.conf"
run "sysctl -a"
dump "/etc/sysctl.conf"
run "lveps -p"
dump "/etc/container/ve.cfg"
dump "/etc/sysconfig/lvestats"
dump "/etc/sysconfig/lvestats2"
dump "/etc/sysconfig/lvestats2.readonly"
run "ls -l /etc/cpanel/ea4"
dump /etc/cpanel/ea4/php.conf
dump /etc/cpanel/ea4/paths.conf
dump /etc/mdadm.conf
run "sar -W -f /var/log/sa/sa$(date +%d)"
run "sar -W -f /var/log/sa/sa$(date +%d -d yesterday)"
run "sar -q -f /var/log/sa/sa$(date +%d)"
run "sar -q -f /var/log/sa/sa$(date +%d -d yesterday)"
run "sar -u -f /var/log/sa/sa$(date +%d)"
run "sar -u -f /var/log/sa/sa$(date +%d -d yesterday)"
run "ls -l /usr/share/cagefs/.cpanel.multiphp/opt/cpanel/ea-php*/root/usr/bin/*php*"
run "ls -l /usr/share/cagefs/.cpanel.multiphp/opt/cpanel/ea-php*/root/etc/php.ini*"
run "ls -l /opt/cpanel/ea-php*/root/usr/bin/*php*"
run "ls -l /opt/cpanel/ea-php*/root/etc/php.ini*"
run "find /etc/cl.php.d -ls"
for file in `ls /etc/sysconfig/lvestats.config/*.cfg 2>/dev/null`; do
dump $file
done
run "tail -n 100 /var/log/lve-stats.log"
run "tail -n 500 /var/log/up2date"
run '/opt/alt/python27/bin/python -c "from lvestats.lib.ustate import get_lveps; print get_lveps()"'
run "ls -la /etc/cl.selector"
dump "/etc/cl.selector/defaults.cfg"
dump "/etc/cl.selector/selector.conf"
dump "/etc/container/mysql-governor.xml"
run 'tail -n20 /var/log/dbgovernor-error.log'
run 'tail -n500 /var/log/yum.log'
run 'getent group linksafe'
run 'repquota -a'
dump '/etc/container/cl-quotas.dat'
run 'cldiag --all'
get_main_ip
detect_cp
apache_info
apache_modules
apache_status
apache_fullstatus
cPanel_forkbomb
echo "Uploading..."
echo -n "Key: "
upload
cleanup
echo "Please, provide above mentioned key to CloudLinux Support Team"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment