top of page
Search

Scripts

  • knowledgediary4min
  • Mar 22, 2020
  • 5 min read

#not wordpress site


grep shop2vizag.com /var/log/messages | awk '{print $6}' | cut -d: -f1 |sort -n |uniq -c |sort -n




#Domains using maximum cPU


echo -e "Number of Days? \c"; read NUMBEROFDAYS;DOMAINS=$(awk -F: '{print $1}' /etc/trueuserdomains);for DOMAIN in $DOMAINS;do for i in $(seq 1 $NUMBEROFDAYS ); do let i=$i+1 ; let k=$i-1 ; let s="$(date +%s) - (k-1)*86400"; let t="$(date +%s) - (k-2)*86400";/usr/local/cpanel/bin/dcpumonview $(date -d @$s +%s) $(date -d @$t +%s) | sed -r -e 's@^<tr bgcolor=#[[:xdigit:]]+><td>(.*)</td><td>(.*)</td><td>(.*)</td><td>(.*)</td><td>(.*)</td></tr>$@Account: \1\tDomain: \2\tCPU: \3\tMem: \4@' | sed "s/^/$(date -Idate -d @$s): /" | grep "Domain: $DOMAIN";done;done | sort -k 1,1 -k 9,9nr;unset NUMBEROFDAYS;unset DOMAINS


#connections to port 80


netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -f1 -d: | sort | uniq -c | sort -rn | head


#Sort the access


awk '{print $1}' | sort -n | uniq -c | sort -n


# brute force script


fgrep -e wp-login -e xmlrpc /usr/local/apache/domlogs/* | grep -v ftp | grep -v 404 | awk '{print $1 " " $7}' | sort | uniq -c | sort -rn | head -n 10


#cat /usr/local/apache/domlogs/* | awk '{print $1}' | sort -n | uniq -c | sort -n



# to check whether mail queue is > 500 then mail to customer


#!/bin/bash


exiqgrep -z -i | xargs exim -Mrm

if [ `exim -bpc` -ge 100 ]

then echo "Exim queue at `exim -bpc`" | /bin/mail -s "Exim queue" myuser@mydomain.com

else

:

fi

(02:24:21 PM) sumith.sn: chmod +x /root/eximqueue.sh






# to rsync every 5 hours :


>create a new : vi rsync.sh, chmod +x rsync.sh

>insert

===

for i in $(/bin/ls /var/cpanel/users/); do rsync -av --log-file=/var/log/rsync.log root@96.30.7.228:/home/$i/ /home/$i/; done

===

>set cron tab

===

0 */5 * * * /root/rsync.sh

===







#entire contents in /home/user that uses maximum memory


/home/cehurdo]# du -ach --max-depth=2 | grep ^[0-9.]*G



#Each users that takes maximum memory


/home]# du -ach --max-depth=1



#Usage in a particular folder


/home]# du -ach /folder name/ --max-depth=1 | grep ^[0-9.]*G



#space utilized by a all files inside that folder


/var/log](Enter into that file)


# du -ach --max-depth=1 | sort -nr | grep ^[0-9.]*M




Basic Commands


du -h --exclude=/home/virtfs / | grep ^[0-9.]*G



du -ach --max-depth=2 | grep ^[0-9.]*G








# prevent file with /fla extension to execute in the server


<Files ~ "\.fla$">

Order allow,deny

Deny from all

</Files>





echo "Detailed Inode usage for: $(pwd)" ; for d in `find -maxdepth 1 -type d |cut -d\/ -f2 |grep -xv . |sort`; do c=$(find $d |wc -l) ; printf "$c\t\t- $d\n" ; done ; printf "Total: \t\t$(find $(pwd) | wc -l)\n"


echo "Detailed Inode usage for: $(pwd)" ; for d in `find -maxdepth 1 -type d |cut -d\/ -f2 |grep -xv . |sort`; do c=$(find $d |wc -l) ; printf "$c\t\t- $d\n" ; done ; printf "Total: \t\t$(find $(pwd) | wc -l)\n"







echo -e "Hai" | mail -s "test" support@wiredtree.com


OR


mail -v senderid



https://www.godaddy.com/help/what-does-my-email-bounceback-mean-3568 > mail issues




# PHP script


<?php

// the message

$msg = "First line of text\nSecond line of text";


// use wordwrap() if lines are longer than 70 characters

$msg = wordwrap($msg,70);


// send email

mail("someone@example.com","My subject",$msg);

?>






echo ""; echo "Server Status One-liner"; echo ""; echo "Storage: "; df -h | sed -n '2,2p' | awk '{print "Disk:",$3"/"$2,$5}'; df -i | sed -n '2,2p' | awk '{print "Inodes:",$3"/"$2,$5}'; echo ""; echo "Load Average: "; cat /proc/loadavg; echo -ne "Thread Count: "; cat /proc/cpuinfo | grep processor | wc -l; echo ""; echo "Usage: "; mpstat | tail -2; echo ""; echo "Memory: "; free -m; echo ""; echo "Vmstat: "; vmstat; echo ""; echo "Services: ";ps cax | grep mysqld > /dev/null; if [ $? -eq 0 ]; then echo "mysql is running"; else echo "mysql is not running"; fi; ps cax | grep httpd > /dev/null; if [ $? -eq 0 ]; then echo "httpd is running"; else echo "httpd is not running"; fi; ps cax | grep exim > /dev/null; if [ $? -eq 0 ]; then echo "exim is running"; else echo "exim is not running"; fi; ps cax | grep named > /dev/null; if [ $? -eq 0 ]; then echo "named is running"; else echo "named is not running(Are they root?)"; fi; ps cax | grep pure-ftpd > /dev/null; if [ $? -eq 0 ]; then echo "ftpd is running"; else echo "ftpd is not running"; fi; ps cax | grep courier > /dev/null; if [ $? -eq 0 ]; then echo "courier is running"; else echo "courier is not running"; fi; netstat -tunap | grep -v 0.0.0.0 | awk '/.*[0-9]+.[0-9]+.[0-9]+.[0-9].*/{gsub(/::ffff:/,"",$0);print $4"\t" $5 "\t" $6"\t" $7}' | awk -F"/" '{print $1"\t"$2}' > netstat.log; echo ""; echo "Connections:";echo "Number of connections to each port:";cat netstat.log | awk {'print $1'} | cut -d: -f 2 | sort | uniq -c | sort -nk 1;echo;echo "Number of connections from each IP:";cat netstat.log | awk {'print $2'} | cut -d: -f 1 | sort | uniq -c | sort -nk 1;echo;echo "Number of instances of a particular IP connecting to particular port with connection states:";cat netstat.log | awk -F":" {'print $2 "\t" $3'} | awk {'print $1 "\t" $2 "\t" $4 "\t" $6'} | sort | uniq -c | sort -nk 1;echo;echo "SYN_RECV connections:";cat netstat.log | awk -F":" {'print $2 "\t" $3'} | awk {'print $1 "\t" $2 "\t" $4 "\t" $6'} | sort | uniq -c | sort -nk 1 | grep SYN_RECV; echo "Most CPU Intensive:"; ps auxf | sort -nr -k 3 | head -2;echo; echo "Most Memory Intensive:"; ps auxf | sort -nr -k 4 | head -2;








command to detect files uploaded onlast week


>> find . -type f -name '*.php' -mtime -7


http://www.gregfreeman.io/2013/how-to-tell-if-your-php-site-has-been-compromised/






##Appending a line into wp-config file

---------------------------------------------


>> find /home/*/public_html -name wp-config.php -type f {finding all files that contains wp-config.php}

>> vi test



=============================================================================================

testing single file


>> echo "define('WP_AUTO_UPDATE_CORE', false)" >> /home/sportbase/public_html/wp-config.php

>> cat /home/sportbase/public_html/wp-config.php {check if define('WP_AUTO_UPDATE_CORE', false) is present}


------------


>> for i in `cat test` ; do cp -pv $i $i.bk ; done {taking backup of single wp-config.php file}

=============================================================================================


>> for i in `cat test` ; do cp -pv $i $i.bk ; echo "define('WP_AUTO_UPDATE_CORE',false);" >> $i ; done





# Memory usage of resources


ps aux | while read line;do PID=$(echo $line | awk '{print $2}');MEMORY_USED="$(ps -o rss $PID | tail -n 1 | awk '{print $1 ": " $1/1024 "M"}')";PROC_NAME=$(echo $line | sed 's/.*[0-9]:[0-9][0-9] \([a-Z\/[:punct:]][^ ]\{1,\} \?\).*/\1/');OOM_SCORE=$(cat /proc/${PID}/oom_score);echo "${MEMORY_USED} (${OOM_SCORE}) ${PROC_NAME/*\//}" | awk -v memv=${MEMORY_USED//[^[0-9\.]/} '{if (memv > 0) print}';done | sort -rnk 1 | awk '{print $0;total += $2;} END {print "Total: " total " M";}' | awk {'print $2,$3,$4,$5'} | head -30


# Memory usage of domains


echo -e "Number of Days? \c"; read NUMBEROFDAYS;DOMAINS=$(awk -F: '{print $1}' /etc/trueuserdomains);for DOMAIN in $DOMAINS;do for i in $(seq 1 $NUMBEROFDAYS ); do let i=$i+1 ; let k=$i-1 ; let s="$(date +%s) - (k-1)*86400"; let t="$(date +%s) - (k-2)*86400";/usr/local/cpanel/bin/dcpumonview $(date -d @$s +%s) $(date -d @$t +%s) | sed -r -e 's@^<tr bgcolor=#[[:xdigit:]]+><td>(.*)</td><td>(.*)</td><td>(.*)</td><td>(.*)</td><td>(.*)</td></tr>$@Account: \1\tDomain: \2\tCPU: \3\tMem: \4@' | sed "s/^/$(date -Idate -d @$s): /" | grep "Domain: $DOMAIN";done;done | sort -k 1,1 -k 9,9nr;unset NUMBEROFDAYS;unset DOMAINS



# Total usages


more /proc/meminfo




ind var/ media/ pub/ -type d -exec chmod -R 777 {} \;



https://www.simpleservers.co.uk/clients/whmcs/knowledgebase/24/How-to-resolve-the-file-permissions-error-in-Magento-Connect-Manager.html



For directories only do this.


find . -type d -exec chmod 755 {} \;


For files only do this.


find . -type f -exec chmod 644 {} \;




SED COMMAND


sed -i 's/original/new/g' file.txt

Explanation:


sed = Stream EDitor

-i = in-place (i.e. save back to the original file)

The command string:

s = the substitute command

original = a regular expression describing the word to replace (or just the word itself)

new = the text to replace it with

g = global (i.e. replace all and not just the first occurrence)

file.txt = the file name



REPLACE COMMAND


replace "old" "new" -- test.php



# To get the details from logs in between date 12 to 13


grep '1[2-3]/Dec/2016'


#To get the details from logs on specific date, specific time


grep "18/Apr/2017" /usr/local/apache/domlogs/clonezone/clonezonedirect.co.uk-ssl_log | awk {'print $1'} | cut -d: -f1 | sort | uniq -c | sort -nr | head


grep "18/Apr/2017:0[4-5]" /usr/local/apache/domlogs/clonezone/clonezonedirect.co.uk-ssl_log | awk {'print $1'} | cut -d: -f1 | sort | uniq -c | sort -nr | head -25

 
 
 

Recent Posts

See All
clear script

#!/bin/bash rm -f ./cleanspace.sh bold=$(tput bold) normal=$(tput sgr0) TIMESTAMP=$(date +%d-%m-%Y-%H-%M) LOGFILE="/root/cleardisk-$TIME...

 
 
 
innodb restore

Create a new folder: mkdir /var/lib/mysql2 From R1: Restore from the /var/lib/mysql folder: + The folder which is called the db name...

 
 
 
Wordpress basic scripts

Site URL and Home URL SELECT * from wp_options WHERE option_name = 'home' OR option_name = 'siteurl'; update wp_options set option_value...

 
 
 

Comments


  • White Facebook Icon
  • White Twitter Icon
  • White Instagram Icon
  • White YouTube Icon

© 2023 by Knowledge4mind. Proudly created with Wix.com

bottom of page