Skip to content

Instantly share code, notes, and snippets.

View hebertluiz's full-sized avatar
🏠
Working from home

Hebert Luiz hebertluiz

🏠
Working from home
View GitHub Profile
@hebertluiz
hebertluiz / wait_for_host.sh
Last active October 14, 2022 20:33
Wait for host up before doing stuff Shellscript | Linux
target_host='google.com'
interval=2
printf '\nWaiting for host %s' "${target_host}"
while true; do
if ping -c 2 -i .1 -W .5 ${target_host} > /dev/null; then
printf '\rHost is %s up. Time to continue' "${target_host}"
break
fi
@hebertluiz
hebertluiz / ANSI.md
Created August 1, 2022 18:50 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@hebertluiz
hebertluiz / secure_dir_httpd.sh
Last active June 20, 2022 18:10
Secure Apache Dir
#!/bin/bash
###### Variables
httpd_config='/etc/httpd'
PASSWD_FILE="/etc/httpd/passwd/${PASSWD_FILE:-passwords}"
httpd_home='/var/www/html'
programname="$(basename -- "$0")"
INDEX='-Indexes'
@hebertluiz
hebertluiz / pprint_csv
Last active September 2, 2021 17:37
Pretty print CSV Bash Func
#!/bin/bash
infile="$*"
if [ -n "$infile" ]
then
if [ -f "$infile" -a -r $infile ]
then
sed -e 's/[,;]\([,;]\)/ \1/g;' "$infile" | tr -d \"\'\` | column -t -s\;, |less
else
@hebertluiz
hebertluiz / install_package.sh
Last active July 8, 2022 21:52
Function to help install yum packages in scripts and show progress
install_packages () {
yum install -y -q "$@" &
yum_pid=$!
spin='-\|/'
i=0
while kill -0 "${yum_pid}" 2>/dev/null; do
i=$(( (i+1) %4 ))
@hebertluiz
hebertluiz / term_colors.sh
Last active August 14, 2021 06:01
tput terminfo basic color reference
set_color () {
local arg2
case $2 in
bg|background)
arg2=setb
;;
*)
arg2=setf
esac
@hebertluiz
hebertluiz / gs_tools.sh
Created November 1, 2019 15:28
Configure Grandstream phone GXPXXXX via curl
function gs_set_config() {
form=''
IP="${1}"
options_list="${2}"
RET=''
if [ -z "$MAX_TRIES" ]; then
MAX_TRIES=5
fi
@hebertluiz
hebertluiz / Sort_and_Count_in_bash
Created September 27, 2019 18:04
Sort_and_Count_in_bash
## To sort a file content and count use the commands below
sort list.txt | uniq -c
11 Sep 24
21 Sep 25
6 Sep 26
2 Sep 27
# The flag -c in the uniq command returns the total count of equal and consecutive entries
@hebertluiz
hebertluiz / PowerShell_batch_rename_files.txt
Created January 18, 2019 17:20
File rename batch powershell
# Expecify below the filetype (extension)
# Change the expression {0:D3} to alter the naming scheme
$i=1; Get-ChildItem *.jpg | %{Rename-Item $_ -NewName ('{0:D3}.jpg' -f $i++)}
@hebertluiz
hebertluiz / bash_cmd_edit_shortcuts.txt
Last active January 31, 2023 08:37
Bash navigation shortcuts
List of quick navigation on long comands in the bash terminal
Reference: https://www.skorks.com/2009/09/bash-shortcuts-for-maximum-productivity/
Ctrl + a – Go to the start of the command line
Ctrl + e – Go to the end of the command line
Ctrl + k – Delete from cursor to the end of the command line
Ctrl + u – Delete from cursor to the start of the command line
Ctrl + w – Delete from cursor to start of word (i.e. delete backwards one word)
Ctrl + y – Paste word or text that was cut using one of the deletion shortcuts (such as the one above) after the cursor
Ctrl + xx – Move between start of command line and current cursor position (and back again)