Tags » Shell Script

A crazy command line

Here is a piece of code from unix.stackexchange which counts the number of occurrences of words in a text file.

sed -e 's/[^[:alpha:]]/ /g' vader.txt | 202 more words
Unix

Shell Scripting: Updates - Part 2

Where I¬†work we don’t have anything like Red Hat Satellite to deploy updates to our thirteen Red Hat servers. So that I don’t have to touch each server manually to apply updates in a relatively controlled fashion, I wrote some shell scripts that will connect to each server, apply updates and then ask if you want to reboot. 848 more words

Linux

Shell Scripting: Updates - Part 1

One thing I have learned with shell scripting is that it’s a wonderful tool to use for automation. What I mean by that is that it’s perfect for promoting less typing. 687 more words

Linux

drop all mysql databases

#!/bin/bash
# Remove all mysql databases

echo 'Enter MySQL user'
read MYSQL_USER

echo 'Enter MySQL password'
stty -echo
read MYSQL_PASSWD
stty echo

DATABASES=$( mysql -u $MYSQL_USER -p$MYSQL_PASSWD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database )

for i in ${DATABASES[*]}; do

  if [ $i != 'mysql' ] && [ $i != 'information_schema' ] && [ $i != 'performance_schema' ]; then

    echo $( date +%H:%M ) drop database: $i 
    time mysql -u $MYSQL_USER -p$MYSQL_PASSWD -e "DROP DATABASE $i"
  fi
done
Shell Script

concatenate variable shell script

VAR=abc; echo ${VAR}def

for i in {1..5}; do echo x${i}x; done
Shell Script

script to recalculate vmware disk size

#!/bin/bash
# Recalculate vmware thin disk size

# Creates zero-block file in all free disk space 
for i in $(df | grep '^/dev/' | awk '{print $6}'); do
  if [ $i == '/' ];then
    echo 'creating a file of blocks zeroed in:' ${i}zerofile
    dd if=/dev/zero of=${i}zerofile bs=4096; rm -f ${i}zerofile
  else
    echo 'creating a file of blocks zeroed in:' $i/zerofile
    dd if=/dev/zero of=$i/zerofile bs=4096; rm -f $i/zerofile
  fi
done
… 18 more words
Shell Script

CPU, Memory Usage by Apache

APACHE PROCESSES THAT CPU OR MEMORY IS LARGER THAN 0

ps -A --sort -rss -o pid,comm,pmem,pcpu,lstart | grep httpd | awk '($3>0) || ($4>0)'

TOTAL CPU USED BY THE APACHE PROCESS… 46 more words

Shell Script