Skip to main content

Linux Bash Scripts

##### Apache Webserver memory usage #####
# Ubuntu
ps -ylC apache2 | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Process Size (MB): "x/((y-1)*1024)}'
# RHEL
ps -ylC httpd | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Proccess Size (MB): "x/((y-1)*1024)}'
##### mysqldump #####
mysqldump testdb $(mysql -Ne 'show tables' | grep -vP '^(history|sessions|watchdog|cache.*)$') | gzip > testdb.sql.gz
##### wordpress permissions #####
find . -type d -exec chmod 755 {} \;  # Change directory permissions rwxr-xr-x
find . -type f -exec chmod 644 {} \;  # Change file permissions rw-r--r--
# you may put your wp-content on 775. 
##### opening screen instances #####
for host in 104test{01..04} 104srv{01..08}; do screen s $host; done
##### list all tar.gz files by size #####
find / -name "*.tar.gz" -printf "%s %p\n"|sort -nr
##### disk usage scripts #####
du -sk * |sort -nr |cut -f2 |xargs -d '\n' du -hs
du -hcx --max-depth=5 / | grep [0-9]G | sort -n -r
##### Basic SQL #####
mysql -u root -p (login to mysql)
mysql> show databases;
mysql> use wp-database; (your wordpress database)
mysql> show tables;
mysql> describe wp_users;
mysql> SELECT ID, user_login, user_pass FROM wp_users;