Skip to content

Instantly share code, notes, and snippets.

@nutrino
Last active May 8, 2023 14:28
Show Gist options
  • Select an option

  • Save nutrino/02fb597826cb0d8a6cf1c00c3815ade1 to your computer and use it in GitHub Desktop.

Select an option

Save nutrino/02fb597826cb0d8a6cf1c00c3815ade1 to your computer and use it in GitHub Desktop.
Linux useful scripts
# https://news.hada.io/topic?id=7286
alias df='df -h -x tmpfs -x devtmpfs -x squashfs'
alias xc='xclip -sel clipboard'
alias ttfb='curl -so /dev/null -w "HTTP %{http_version} %{http_code} Remote IP: %{remote_ip}\nConnect: %{time_connect}\nTTFB: %{time_starttransfer}\nTotal time: %{time_total}\nDownload speed: %{speed_download}bps\nBytes: %{size_download}\n"'
ap() {
https $@ Accept:application/activity+json
}
shodan() {
xdg-open https://shodan.io/domain/$1
dig +short $1 | xargs -i xdg-open https://shodan.io/host/{}
}
check_mtu() {
local target=$1
shift
local lower=0
local upper=1500
until [[ $((lower + 1)) -eq $upper ]]; do
current=$(((lower + upper) / 2))
echo -n "lower: $lower, upper: $upper, testing: $current -- "
if ping -M do -s $current -c 2 -i 0.2 $target $@ &>/dev/null; then
echo "ok"
lower=$current
else
echo "fail"
upper=$current
fi
done
echo "max packet size: $lower, mtu: $((lower + 28))"
}
# https://news.hada.io/topic?id=9118
killport() {
if [ $# -ne 0 ]; then
for port in "$@"; do
pids=$(lsof -ti ":$port")
if [ -n "$pids" ]; then
echo "Processes listening on port $port: $pids"
echo "$pids" | xargs kill -9 >/dev/null 2>&1
echo "Processes listening on port $port have been terminated"
else
echo "No process found listening on port $port"
fi
done
else
echo "No arguments provided"
fi
}
@nutrino
Copy link
Author

nutrino commented Nov 19, 2022

lsof -i -P | grep -i "listen"

lsof -t -i TCP:8080 | xargs kill -9

netstat -an |grep LISTEN

@nutrino
Copy link
Author

nutrino commented Nov 20, 2022

nmcli connection show

@nutrino
Copy link
Author

nutrino commented Dec 13, 2022

#!/bin/bash

if [ -z "$1" ]; then
echo "sudo yumoffline.sh [packageName]"
exit 1
fi

if [ "$EUID" -ne 0 ]
then echo "Please run as root (sudo yumoffline.sh [packageName])"
exit
fi

set -x #echo on

@nutrino
Copy link
Author

nutrino commented Feb 19, 2023

Ubuntu Network

ip addr set enp4s0 up
nmtui
sudo lshw -C network

@nutrino
Copy link
Author

nutrino commented Feb 21, 2023

Boot kernel log

dmesg

@nutrino
Copy link
Author

nutrino commented Feb 21, 2023

sudo nano /etc/systemd/system/autostart-mount.service

[Unit]
Description=Mount Share at boot
After=network.target

[Service]
User=root
ExecStart=/bin/mount -a
ExecStartPre=/bin/sleep 10
Restart=on-failure

[Install]
WantedBy=multi-user.target

@nutrino
Copy link
Author

nutrino commented Feb 21, 2023

sudo nano /etc/systemd/system/jupyterlab.service

[Unit]
Description=JupyterLab
After=syslog.target network.target

[Service]
User=root
Environment="PATH=/usr/local/bin:/usr/bin:/bin"
ExecStart=/usr/local/bin/jupyter lab --ip 0.0.0.0 --port 8888 --no-browser --allow-root
#ExecStart=/usr/local/bin/jupyter notebook --ip 0.0.0.0 --port 8888 --no-browser --allow-root
#ExecStart=/usr/local/bin/jupyterhub --ip 0.0.0.0 --port 8888
ExecStartPre=/bin/sleep 20

[Install]
WantedBy=multi-user.target

@nutrino
Copy link
Author

nutrino commented Mar 3, 2023

script -c "ls --color=auto" output.txt

@nutrino
Copy link
Author

nutrino commented Mar 4, 2023

change wayland to X11
rustdesk/rustdesk#670
sudo nano /etc/gdm3/custom.conf

@nutrino
Copy link
Author

nutrino commented Apr 18, 2023

systemctl status display-manager.service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment