massping script

just a little script which pings a defined number of servers a defined time and give you the result. Good for looking if you connection is stable or if it may be an internet problem.

#!/bin/bash

targets=( 1.1.1.1 8.8.8.8 cloudflare.com discord.com )
max=100


tmpfile=$$.massping.tmp

# functions
f_ping(){
  v=$(ping -c $max $1 2>/dev/null|grep received|cut -d' ' -f4)
  echo $1 $v >> $tmpfile
}

f_done(){
  [[ ! -f $tmpfile ]] && echo false && return
  [[ $(wc -l $tmpfile 2>/dev/null|cut -d' ' -f1) -eq ${#targets[@]} ]] && echo true && return
  echo false
}

# main
for s in ${targets[@]}; do
  f_ping $s &
done

c=$max; echo
while [[ $(f_done) == false ]]; do
  echo -e "\e[1A\e[Kwaiting. This should need $c more seconds.."
  c=$(( $c - 1 ))
  sleep 1
done
echo -e "\e[1A\e[Kdone"; echo

maxline=0; for w in $(cat $tmpfile|cut -d' ' -f1); do [[ ${#w} -gt $maxline ]] && maxline=${#w}; done
spaces=""; while [[ $(( ${#spaces} + 1 )) -lt $maxline ]]; do spaces="$spaces "; done
echo "server${spaces}%"
IFS="
"
while read -r line; do
  server=$(echo $line|cut -d' ' -f1)
  count=$(echo $line|cut -d' ' -f2)
  perc=$(echo "scale=1; $count * 100 / $max"|bc)
  spaces=""; while [[ $(( ${#spaces} + ${#server} - ( 5 - ${#perc} ) )) -lt $maxline ]]; do spaces="$spaces "; done
  echo "${server}${spaces} ${perc}"
done < $tmpfile

[[ -f $tmpfile ]] && rm -f $tmpfile

exampleoutput:

server             %
1.1.1.1        100.0
8.8.8.8        100.0
cloudflare.com  99.0
discord.com     85.0

portforwarting over ssh

To use SSH tunneling in Linux, you need to provide your client with the source and destination port numbers, as well as the location of the destination server. The location can either be an IP address or a hostname.

The basic syntax for a local port forward command is straightforward:

ssh -L <local_port>:<target_server>:<targetport> <user>:<ssh_server> -p<sshport>

source: [link]

repair grub2 on software-raid system

Assumptions:
– fs / is on /dev/md2
– fs boot is on /dev/md1
– you are using 2 harddisks (sda, sdb)
– you are using grub2
– grub2 is nor working (fe: error: symbol ‘grub_calloc’ not found.)


First boot your system with a rescue-disk/livecd. Then:

# mount /dev/md2 /mnt
# mount /dev/md1 /mnt/boot
mount --bind /proc /mnt/proc/ ; mount --bind /dev /mnt/dev/ ; mount --bind /sys /mnt/sys/
# chroot /mnt
# grub2-install /dev/sda   # or /dev/nvme1n1 - depends on your disks :)
# grub2-install /dev/sdb

you should see “Installing for i386-pc platform. Installation finished. No error reported.”

reboot.