set -e
set -o pipefail
# -e (errexit): Abort script at first error, when a command exits with non-zero status (except in until or while loops, if-tests, list constructs)
# In case script is calling subscript inside, the pipefail option can be useful.
# -o pipefail: Causes a pipeline to return the exit status of the last command in the pipe that returned a non-zero return value.
du -sh /* 2> /dev/null
HERE=$(dirname `which $0`)
echo "Current directory is $HERE"
pushd `dirname $0` > /dev/null
HERE=`pwd -P`
popd > /dev/null
echo "Current directory is $HERE"
sudo kill `ps aux | grep node | awk '{print $2}'`
url="my.hostname.com"
echo "Waiting for $url"
while ! curl --max-time 3 http://$url
do
sleep 1
done
function wait_url_return_200()
{
URI=$1
TIMEOUT=30
ATTEMP=0
while [ $(curl --write-out %{http_code} --silent --output /dev/null $URI) != "200" ]
do
ATTEMP=$((ATTEMP + 1))
echo " wait $URI become available... $ATTEMP/$TIMEOUT"
if [ "$ATTEMP" == "$TIMEOUT" ]; then
echo "Timeout Error"
return 1;
fi
sleep 1
done
return 0;
}
# Usage:
wait_url_return_200 https://g00gle.com
echo "Res $?";
URI=https://www.wikipedia.org/
RES=$(curl --write-out %{http_code} --silent --output /dev/null $URI)
if [ "200" == "${RES}" ];
then
echo "Successfully $RES"
else
echo $RES
fi
while [ $(curl --write-out %{http_code} --silent --output /dev/null $URI) != "200" ]
do
echo "wait..."
sleep 1
done
if [ $(id -u) -ne 0 ] ; then
echo "You must be root to run this install"
exit 1
fi
bash script.sh 2>&1 | tee script.log
tail -f /var/log/syslog
tail -F /var/log/syslog # for files under rotation
history 1> commands.log
history 5 1> commands.log # last 5 comands
history | grep docker 1> commands.log # *docker* commands
ES=0.0.0.0:9200
curl -XDELETE "http://$ES/pint/"
for e in ./data/*.elastic ; do
echo "$e"
curl -s -XPOST http://$ES/_bulk --data-binary "@$e" > /dev/null
done
sudo su
setcap 'cap_net_bind_service=+ep' `readlink -f $(which java)`
touch /home/ubuntu/.ssh/known_hosts
ssh-keyscan github.com >> /home/ubuntu/.ssh/known_hosts
file=/etc/ssh/sshd_config
val=KexAlgorithms=diffie-hellman-group1-sha1
sudo grep -q -F $val $file || sudo echo $val >> $file # Add line to file if it not exists
sudo systemctl restart sshd
lab=10.10.10.10
sshKey=....pem
ssh -i $sshKey -o StrictHostKeyChecking=no ubuntu@$lab <<'ENDSSH'
sudo su
file=/etc/ssh/sshd_config
val=KexAlgorithms=diffie-hellman-group1-sha1
grep -q -F $val $file || echo $val >> $file
systemctl restart sshd
ENDSSH
echo arg1 arg2 arg3 | xargs -n 1 -P 3 bash ./build.sh
Equivalent of next code run in parallel:
bash ./build.sh arg1
bash ./build.sh arg2
bash ./build.sh arg3
Any number of parallel tasks:
TASKS=(arg1 arg2 arg3)
echo ${TASKS[*]} | xargs -n 1 -P ${#TASKS[*]} bash ./build.sh