Table of contents

Recurring commands

%3 cluster_5356b564_e99d_451c_a410_10c7074b8200 Recurring commands cluster_4290b15a_e388_455d_8163_477c74888b5e Get certificate data from domain cluster_96b52075_e9cc_4ffe_bb63_d8fc877291a9 Copy command output to clipboard _7dac7e56_5509_4f01_9431_51c3140599f5 Check webcam funcionality _34e7051a_5385_41d0_85c9_907d2c8d7a86 Get program progress reading a file _63c23115_8fbf_42b1_8f94_eee55006a01a Get certificate expiration date _6ff44843_6cd9_4697_af31_4c68f432a817 Bridge two TCP ports _d0a5f394_18f5_42a5_8f4d_c6c6a2a31650 Configure default browser _f92789e5_1324_46a2_865c_1d0fc2c76c81 Wayland _3149bce3_10ea_40af_bc78_d9ebc2eac25a X11 _5f0ab10d_bea5_42e0_9e51_29bf1b97cd07 Set timezone _11380731_d635_4a0f_8d4b_6ea94576c5db bash _ea48ec1d_f9d4_4fb7_b39a_faa7b6e2ba95 Notes index _ea48ec1d_f9d4_4fb7_b39a_faa7b6e2ba95->__0:cluster_5356b564_e99d_451c_a410_10c7074b8200 __1:cluster_5356b564_e99d_451c_a410_10c7074b8200->_11380731_d635_4a0f_8d4b_6ea94576c5db

Bridge two TCP ports

Connect local port 9999 to 22 on 192.168.1.2. More documentation

socat tcp-listen:9999,reuseaddr,fork tcp-connect:192.168.1.2:22

Copy command output to clipboard

X11

$COMMAND | xclip -in -sel clip

Wayland

$COMMAND | wl-copy

Get certificate data from domain

DOMAIN=codigoparallevar.com
openssl s_client -connect $DOMAIN:443 </dev/null

Get certificate expiration date

DOMAIN=codigoparallevar.com
openssl s_client -connect $DOMAIN:443 </dev/null 2>/dev/null | openssl x509 -noout -dates

Get program progress reading a file

  • On post

    Leer el progreso de lectura de un archivo

#!/usr/bin/env bash

# Check that we have at least a PID
if [ -z "$1" ];then
   echo "$0 <PID> [<FD>]"
   exit 1
fi

set -eu  # Bail on any error
PID=$1
FD=${2:-} # Take FD if we have second parameter, else consider it empty

if [ -z "$FD" ];then
   # Show the user the available file descriptors
   echo "Select a file descriptor:"
   for i in /proc/$PID/fd/*;do
       printf "  %s: " $(basename $i)
       readlink $i
   done

   read -p "FD: " FD
fi

FSIZE=$(stat -L /proc/$PID/fd/$FD --printf=%s)  # Read full file size
while [ 1 ];do

      # Stop if the process has finished reading the file
      if [ ! -f /proc/$PID/fdinfo/$FD ];then
         break
      fi

      # Read position on file
      x=$(cat "/proc/$PID/fdinfo/$FD"|grep pos: |cut -d: -f2|tr -d '\t ')

      # Convert that position into a % of the file size
      PER10000=$(( $x * 10000 / $FSIZE ))
      if [ $PER10000 -le 100 ];then
         # Less than 1%
         printf "  0.%02i%%\n" $(( $PER10000 ));
      else
         # More than 1%
         printf "%3i.%02i%%\n" $(( $PER10000 / 100 )) $(( $PER10000 % 100 ));
      fi

      # Wait for the next loop
      sleep 1
done

Check webcam funcionality

ls -ltr /dev/video*
  • See webcam

mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0 -fps 30

Configure default browser

## Old style
# sudo update-alternatives  --config x-www-browser

## New style
xdg-settings set default-web-browser <desktop file inside ~/.local/share/applications/>

Set timezone

  • See current timezone

timedatectl show|grep Timezone

: Timezone=Europe/Madrid

  • List timezones

timedatectl list-timezones | head

Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Asmera
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau

  • Set timezone

timedatectl set-timezone Europe/Madrid