Here’s a simple little script that displays the number of characters in a string.
#!/bin/bash if [[ $# -eq 0 ]] ; then echo 'Missing arguments'; exit 0; fi var=$1 size=${#var} echo $size |
Command:
./length.sh abcdefghijklmnopqrstuvwxyz |
Output:
26 |
cloud engineer
Here’s a simple little script that displays the number of characters in a string.
#!/bin/bash if [[ $# -eq 0 ]] ; then echo 'Missing arguments'; exit 0; fi var=$1 size=${#var} echo $size |
#!/bin/bash if [[ $# -eq 0 ]] ; then echo 'Missing arguments'; exit 0; fi var=$1 size=${#var} echo $size
Command:
./length.sh abcdefghijklmnopqrstuvwxyz |
./length.sh abcdefghijklmnopqrstuvwxyz
Output:
26 |
26
I decided to log my commands for good record keeping. Here’s my script.
#!/bin/bash if [[ $# -eq 0 ]] ; then echo 'No arguments. Format: ./go.sh script.sh'; exit 0; fi log=log.txt echo '-------------------------------' >> $log date >> $log echo '---' >> $log cat $1 >> $log echo '---' >> $log /bin/bash $1 2>&1 | tee -a $log |
#!/bin/bash if [[ $# -eq 0 ]] ; then echo 'No arguments. Format: ./go.sh script.sh'; exit 0; fi log=log.txt echo '-------------------------------' >> $log date >> $log echo '---' >> $log cat $1 >> $log echo '---' >> $log /bin/bash $1 2>&1 | tee -a $log
To run.
./go.sh script.sh |
./go.sh script.sh
Line by line explanation.
How to create a swap file.
A 2GB swap file.
dd if=/dev/zero of=/swapfile bs=1k count=2048k |
dd if=/dev/zero of=/swapfile bs=1k count=2048k
Activate.
mkswap /swapfile chmod 0600 /swapfile systemctl daemon-reload swapon /swapfile |
mkswap /swapfile chmod 0600 /swapfile systemctl daemon-reload swapon /swapfile
To make swap permanent, add to /etc/fstab.
/swapfile swap swap defaults 0 0 |
/swapfile swap swap defaults 0 0
Check if swap is working.
cat /proc/swaps free -h |
cat /proc/swaps free -h
How to reinstall the latest kernel and rebuild initramfs.
Find the latest kernel.
rpm -qa kernel
kernel-3.10.0-1160.6.1.el7.x86_64
kernel-3.10.0-1160.11.1.el7.x86_64 |
rpm -qa kernel kernel-3.10.0-1160.6.1.el7.x86_64 kernel-3.10.0-1160.11.1.el7.x86_64
Remove the kernel first, then reinstall.
yum remove kernel-3.10.0-1160.6.1.el7.x86_64 yum install kernel-3.10.0-1160.6.1.el7.x86_64 |
yum remove kernel-3.10.0-1160.6.1.el7.x86_64 yum install kernel-3.10.0-1160.6.1.el7.x86_64
Here are a few utilities that monitor disk I/O performance.
iostat -d 5 pidstat -dl 20 iotop --only |
iostat -d 5 pidstat -dl 20 iotop --only
The alternative is atop, which you can set to run every 10 seconds for 3 hours. The output can be viewed later.
atop -a -w logfile.atop 10 10800 & |
atop -a -w logfile.atop 10 10800 &
Use atop to read the log file.
atop -r /path/to/logfile.atop |
atop -r /path/to/logfile.atop