shell_utilities - charlesfg/TPCx-V_setup GitHub Wiki

Shell Utilities

Those scripts and alias are useful shortcuts for access or repetitives task that you certainly will bump into somewhere into your work with TPCx-V.

It's useful to ease the work off inspecting configurations on the VMs.

Premises

  1. Have an /etc/hosts pointing out to each of your VM with the following naming convention:
  • As a regex: tpc-(t[1-6])?g[1-4](a|b[12]?) (I've only used without the tile part t[1-6])
  1. Using xen you have to set the GUEST_DIR_CONFIG or copy the config files to the /etc/xen

Run a command in a TPC guest

  • function runAt that run a shell command into a list of hosts
  • Alias to run at All Vms, All group A or All group B
function runAt(){
    TARGET=$1
    shift;
    for i in `cat /etc/hosts | grep $TARGET | awk '{print $2}'`; do  
        echo $i; 
        ssh $i $@; 
    done
}


alias runatall="runAt tpc-g"
alias runata="runAt tpc-g[0-9]a"
alias runatb="runAt tpc-g[0-9]b"

Copy file to a TPC guest

  • function copyTo that copy files using scp to a list of tpc guest
  • Also alias to copy to: All Vms, All group A or All group B
# Usage :
# $1 ->target filter
# $2 ->directory target
# $3 ->files
function copyTo(){
    TARGET=$1
    shift;
    TARGET_DIR=$1
    shift;
    for i in `cat /etc/hosts | grep $TARGET | awk '{print $2}'`; do  
        echo $i; 
        scp $@ ${i}:${TARGET_DIR} 
    done   
}


alias copytoall="copyTo tpc-g"
alias copytoa="copyTo tpc-g[0-9]a"
alias copytob="copyTo tpc-g[0-9]b"

Add each host to list of known hosts of each vm.

  • After setting up all vms, all above aliases and both root and postgres user perform the following command to avoid getting the unkown host message

echo '
for i in 127.0.0.1 localhost 150.164.203.70 tpc-drive 10.0.0.31 tpc-g1a 10.0.0.32 tpc-g1b1 10.0.0.33 tpc-g1b2 10.0.0.34 tpc-g2a 10.0.0.35 tpc-g2b1 10.0.0.36 tpc-g2b2 10.0.0.37 tpc-g3a 10.0.0.38 tpc-g3b1 10.0.0.39 tpc-g3b2 10.0.0.40 tpc-g4a 10.0.0.41 tpc-g4b1 10.0.0.42 tpc-g4b2; 
do 
    ssh -t -o '"'"'StrictHostKeyChecking no'"'"' $i hostname && uptime;     
done
' > /tmp/accept_host_keys.sh




echo '
for i in `cat /etc/hosts | grep tpc- | awk '"'"'{print $2}'"'"' `; 
do 
    ssh -t -o '"'"'StrictHostKeyChecking no'"'"' $i hostname && uptime;     
done
' > /tmp/accept_host_keys.sh


copytoall /tmp /tmp/accept_host_keys.sh 
runatall 'bash /tmp/accept_host_keys.sh'
runatall 'su -l postgres -c "/bin/bash /tmp/accept_host_keys.sh"'

Xen Specific aliases

  • Alias to start|shutdown all vm or specific groups (A or B )
XEN_VM_CONFIG_HOME=/var/tpcv/tpc_repo/xen_install

alias xshutall="xl list | awk 'NR>2{ print \$1}' | xargs -n1 xl shutdown"
alias xstartall="for c in \$(ls $XEN_VM_CONFIG_HOME/tpc-*); do echo Starting \$(basename \$c) ; xl create \$c; done"

LibVirt Specific aliases

  • Alias to start|shutdown all vm or specific groups (A or B )
alias vshuta="virsh list | grep g[1-9]a | awk '{print \$2}' | xargs -n1  virsh shutdown"
alias vshutb="virsh list | grep g[1-9]b | awk '{print \$2}' | xargs -n1  virsh shutdown"
alias vstartb="virsh list --all | grep g[1-9]b | grep 'shut off' | awk '{print \$2}' | xargs -n1  virsh start"
alias vstarta="virsh list --all | grep g[1-9]a | grep 'shut off' | awk '{print \$2}' | xargs -n1  virsh start"
alias vla='virsh list --all'