A collection of the most used shellscripting tricks.
wc -l file.txt counts the number of linesUseful when you want to free old data/logs.
I use them to quick connect my ssh servers
alias ssh-prod-dc-app1-server1='ssh user@server1'#!/bin/bash
function_name(){
param1=$1
param2=$2
echo $param1
echo "this is param 2 $param1"
}
function_name hello worldfind ./ -name filename.txtwhile true; do date; ps aux|grep ssh;sleep 5;doneuptime - Get server uptime. last - Get who was login into the system.
You can cat the history log from cat ~/.bash_history
To dump everything from iface enp0s3
tcpdump -w dump.pcap -i enp0s3To dump all comes and goes to an specific ip. (Look that with the -i any we can listen all the interfaces)
tcpdump -w dump.pcap -i any host 1.1.1.1The following comand save dump files of 10 mb, and rotate it in 5 files, so we will have as much 10mb x 5 files of dump.
tcpdump -W 5 -C 10 -w capfileGet .pem certificate info
openssl.exe x509 -in cert.pem -noout -textGet public key from .pem certificate
openssl x509 -pubkey -noout -in Cert.pemGenerate selfsigned cert and private key
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365Try to connect to a host using MTLS
openssl s_client -connect <host>:<port> -cert <client_cert>.pem -key <client_cert_key>.key -showcerts -cert_chain <client_cert_chain>.pem