How To Preserve Quotes In Bash Arguments

If you want to preserve quoting to pass shell arguments to a called command, use the four characters “$@” (including the double quotes) instead of the two characters $*
![]() |
If you want to preserve quoting to pass shell arguments to a called command, use the four characters “$@” (including the double quotes) instead of the two characters $*
When using Perl’s exec() call, the best way to invoke it is as follows:
1 |
exec("$dir/myprog.sh",@ARGV); |
This syntax does some important things: – passes a scalar value as the first argument which exec interprets as PROGRAM – passes an array as the second argument which exec will use as the arguments to pass into PROGRAM Note […]
Tungsten Clustering provides high availability, disaster recovery, and a host of other benefits for MySQL / MariaDB / Percona Server databases. In this blog post we will explore some of the shell aliases I use every day to administer various Tungsten Clusters.
There are times when the hackers slam my servers and the load gets too high. I use a very simple bash script as a cron job to monitor the load and take action when it gets too high. The script will stop httpd, sleep for a configurable period of time (currently 3 minutes), then start […]
As always, YMMV…
1 2 3 4 5 6 7 8 9 |
#!/bin/bash # Usage: eject [fullpath to mount point] DISK="${1:-/Volumes/YourUSBFlashDriveName/}" df -h "$DISK" > /dev/null 2>&1 if [ $? -eq 0 ]; then diskutil unmountDIsk `diskutil list "$DISK" | grep ^/dev/` else echo Volume $DISK is not mounted...skipping. fi |
The script to check and restart apache…works on CentOS – YMMV!
1 2 3 4 5 6 7 8 9 10 11 |
#!/bin/bash MAXLOAD=6 check=$(uptime | awk -F'average: ' '{print $2}' | awk '{print $1}' | tr -d ',') if [[ $check > $MAXLOAD ]]; then /sbin/service httpd stop HOST=`hostname` echo $HOST | mailx -s "$HOST load alert - apache STOPPED by cron script" load.alert@your.domain sleep 300 /sbin/service httpd start echo $HOST | mailx -s "$HOST load alert - apache STARTED by cron script" load.alert@your.domain fi |
Add to cron * * * * * /root/restart_apache_if_load_hits_threshold.sh >> /var/log/restart_apache_if_load_hits_threshold.log 2>&1
The Readline library has a bell-style variable that controls what happens when Readline wants to ring the terminal bell. If set to ‘none’, Readline never rings the bell. If set to ‘visible’, Readline uses a visible bell if one is available. If set to ‘audible’ (the default), Readline attempts to ring the terminal’s bell. Edit […]
1 2 3 4 |
#!/bin/bash for line in `cat file.txt`; do echo line: $line done |
1 2 3 4 |
#!/bin/bash for file in $( ls ); do echo filename: $file done |
1 2 3 4 |
#!/bin/bash for i in `seq 1 10`; do echo $i done |
awk ‘{sum+=$1}END{print sum}’ inputFile
This is the standard upgrade method for AWS Linux AMI’s:
1 2 |
yum clean all yum update bash |
Or use this for the version 2012.09, 2012.03, or 2011.09 repositories:
1 2 |
yum clean all yum --releasever=2013.03 update bash |
For older AWS Linux AMI’s, you may not be able to use the standard upgrade method as described in this link: https://alas.aws.amazon.com/ALAS-2014-419.html These are the steps needed to manually patch bash 4.1: […]