growpart /dev/nvme1n1 1
resize2fs /dev/nvme1n1p1
convert $(ls -v *.jpg) foobar.pdf
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf foobar.pdf
bash <(curl -fsSL https://get.docker.com)
docker run -d --rm --name postgres -p 5432:5432 -e POSTGRES_USER=ferdb -e POSTGRES_PASSWORD=pass -e POSTGRES_DB=idms35_fer_20210318_194439 postgres:12
cat idms35_fer_20210318_194439.custom | docker exec -i postgres pg_restore -U ferdb -d idms35_fer_20210318_194439
lsof -i TCP:22
du -Sh / | sort -rh | head -100
du -h -d 1 . | sort -rh | head -100
pwgen -BCnsy -r ''"{}[]<>,./|;:-=_+`$%&()' 16 -1 7
systemctl mask systemd-logind
CREATE USER 'harry'@'%' IDENTIFIED WITH mysql_native_password BY 'superSecretPassword!123';
GRANT ALL ON *.* TO 'harry'@'%' WITH GRANT OPTION;
On the master
# as postgres
$ psql -c "ALTER SYSTEM SET listen_addresses TO '*'";
$ psql -c "CREATE USER replicator WITH REPLICATION ENCRYPTED PASSWORD 'secret'";
$ psql -c "SELECT pg_create_physical_replication_slot('slot1')";
# as root
$ echo "host replication replicator 192.168.0.2/32 md5" >> /etc/postgresql/14/main/pg_hba.conf
$ systemctl restart postgresql@14-main
On the replica
$ systemctl stop postgresql@14-main
$ cd /var/lib/postgres/14/
$ rm -rf main
$ pg_basebackup -h 192.168.0.1 -U replicator -p 5432 -D main -Fp -Xs -P -R -S slot1
$ chown -R postgres:postgres main
$ systemctl start postgresql@14-main
On the master
# as postgres
$ psql -c "SELECT redo_lsn, slot_name,restart_lsn,round((redo_lsn-restart_lsn) / 1024 / 1024 / 1024, 2) AS GB_behind FROM pg_control_checkpoint(), pg_replication_slots";
$ psql -c "select * from pg_stat_replication";
git remote add upstream git@bitbucket.org:r2w1/ready2wear.git
git fetch upstream
git checkout main
git merge upstream/main --allow-unrelated-histories
git push origin main:main
git branch devel
git checkout devel
git merge upstream/devel --allow-unrelated-histories
git push origin devel:devel
sudo tcpdump -A -s 10240 "tcp port 80 and (((ip[- ((ip0<<2)) - ((tcp!= 0)" | egrep -a --line-buffered ".+(GET |HTTP/|POST )|[1](12>>2)))+: " | perl -nle 'BEGIN{$|=1} { s/.?(GET |HTTP/0-9. |POST )/\n$1/g; print }'
sed -n '/^Sep 14 15:09/,/^Sep 14 15:56/p' prod.log
awk -v start_date="Jan 18 11:39:00" -v end_date="Jan 18 11:44:00" '$0 >= start_date && $0 <= end_date' logfile.txt <-- seems to work better
Reference(https://askubuntu.com/a/800774)
find /directory -newermt $(date +%Y-%m-%d -d '1 day ago') -type f -print
edit ~/.vimrc
set mouse-=a
$ filename=foo.txt
$ echo "${filename%.*}"
foo
for i in $(ls); do /bin/mv $i ${i%.*} ; done
docker run --rm -it -v ~/.aws:/root/.aws amazon/aws-cli s3 presign s3://xaos-share/wpmultisite.tar --expires-in 604799
https://aws.amazon.com/premiumsupport/knowledge-center/presigned-url-s3-bucket-expiration/
-S
tar c /var/test | gzip | aws s3 cp - "s3://tests/test1.tar.gz"
https://github.com/minio/console
Create user
mc admin user add myminio/
Enter Access Key: console
Enter Secret Key: xxxxxxxx
Create a policy file policy.json
Full access:
{
"Version": "2012-10-17",
"Statement": [{
"Action": [
"admin:*"
],
"Effect": "Allow",
"Sid": ""
},
{
"Action": [
```
"s3:*"
```
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::*"
],
"Sid": ""
}
]
}
Read only:
{
```
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Action":[
"s3:ListBucket",
"s3:ListAllMyBuckets"
],
"Resource":"arn:aws:s3:::*"
},
{
"Effect":"Allow",
"Action":[
"s3:ListBucket",
"s3:GetObject"
],
"Resource":[
"arn:aws:s3:::*",
"arn:aws:s3:::*/*"
]
}
]
```
}
mc admin policy add myminio/ <policyname> policy.json
Apply the policy to the user
mc admin policy set myminio <policyname> user=console
sudo localectl set-keymap us
Download Java(https://www.java.com/it/download/manual.jsp) from Oracle
extract and run from CLI
./jre1.8.0_321/bin/javaws ./targets.jnlp
Create user:
createuser -p 5432 --interactive --pwprompt -e
Change user password:
psql -p 5432 -c ALTER ROLE myuser WITH PASSWORD 'mypassword';
Create DB with owner:
createdb -p 5432 -O username database
Create DB with owner from template:
createdb -p 5432 -T template -O username database
Dump DB in custom format:
/usr/lib/postgresql/13/bin/pg_dump -p 5432 -Fc -U "$USERNAME" "$DATABASE" -f $BACKUP_DIR"$DATABASE".custom
Restore DB in custom format:
/usr/lib/postgresql/13/bin/pg_restore -p 5432 -Fc database.bak -d database
Dump DB in SQL format:
/usr/lib/postgresql/13/bin/pg_dump -p 5432 -Fp -U "$USERNAME" "$DATABASE" | gzip > $BACKUP_DIR"$DATABASE".sql.gz
Change owner of dump in SQL format:
gunzip databaseDump.sql.gz && sed -i 's/olduser/newuser/g' databaseDump.sql
docker exec -ti $(docker ps | grep frontend | tail -n1 | awk '{print $(NF)}') bash
On host A:
socat -v tcp-l:8181,fork exec:"/bin/cat"
On host B:
nc 127.0.0.1 8181
i=$((i+1))
((i=i+1))
let "i=i+1"
if then else conditionalif something; then
:
else
do something
fi
for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less
grep -v from same filesed -i '/sometext/d' file
or
cat file | grep -v sometext | sponge file
date formatting 2020-07-13T16:24:52+02:00
# date +'%FT%T'
2020-07-13T16:27:06
Ctrl + Shift + U20AC
https://unix.stackexchange.com/a/262092
for SERVERNAME in `grep "server_name " ${PWD}/nginx-proxy/conf.d/default.conf | grep -v invalid | awk '{print $2}' | cut -d ';' -f 1 | uniq`; do
```
echo "location = /wp-login.php {\n auth_basic \"Restricted\";\n auth_basic_user_file /etc/nginx/htpasswd/wp-login;\n proxy_pass http://${SERVERNAME};\n}" >> ${PWD}/nginx-proxy/vhost.d/${SERVERNAME}; done
```
When using Amazon RDS the user issuing the CREATE DATABASE must be a member of the role that will be the owner of the database. In my case, the superuser account I'm using is called root, and I'm going to create a role o which is going to own a database d:
postgres=> CREATE ROLE o;
CREATE ROLE
postgres=> CREATE DATABASE d OWNER = o;
ERROR: must be member of role "o"
postgres=> GRANT o TO root;
GRANT ROLE
postgres=> CREATE DATABASE d OWNER = o;
CREATE DATABASE
Outside the container:
docker pull debian:stable
docker run --privileged --rm -ti debian:stable bash
Inside the container:
apt-get update && apt-get install -y debootstrap xz-utils
targetdir=rootfs
distro=etch
mkdir $targetdir
debootstrap --arch=amd64 --no-check-gpg $distro $targetdir http://archive.debian.org/debian
cd $targetdir && tar cvJf /rootfs.tar.xz .
Outside the container:
docker cp <CONTAINER ID>:/rootfs.tar.xz rootfs.tar.xz
docker build -t etch -f Dockerfile .
docker run --rm -ti etch bash
Dockerfile to build image:
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/bash"]
Reference: https://github.com/johnnymo87/etch
edit wp-config.php
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
$_SERVER['HTTPS']='on';
reference:
https://wordpress.org/support/article/administration-over-ssl/#using-a-reverse-proxy
sudo nmap --script broadcast-dhcp-discover
#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for f in *
do
echo "$f"
done
IFS=$SAVEIFS
reference:
https://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html
SAVEIFS=$IFS; IFS=$(echo -en "\n\b"); for i in $(find -type d -regex ".*ndesiderata\|.*unk\|.*estino\|.*rash\|.*liminata\|.*pam" -exec du -sh {} \;| grep G | awk '{print $2}'); do find $i -type f \! -iname "dovecot*" \! -iname maildirfolder -delete; done; IFS=$SAVEIFS
SAVEIFS=$IFS; IFS=$(echo -en "\n\b"); for i in $(find -type d -regex ".*ndesiderata\|.*unk\|.*estino\|.*rash\|.*liminata\|.*pam"); do find $i -type f -ctime +30 \! -iname "dovecot*" \! -iname maildirfolder -delete; done; IFS=$SAVEIFS
aws ec2 [<profile>](<profile>)(--profile) describe-instances --query 'Reservations[*].Instances[*](*].Instances[*).{<custom label>:<element>}' --filters "Name=tag:<tag name>,Values=<tag value>"
Example:
aws ec2 --profile dlt describe-instances --query 'Reservations[*].Instances[*](*].Instances[*).{IP:PublicIpAddress}' --filters "Name=tag:aws:autoscaling:groupName,Values=DLT-ASG-02"
Reference:
https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-output.html#cli-usage-output-filter
https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html
VBoxManage guestproperty get vm1 "/VirtualBox/GuestInfo/Net/0/V4/IP"
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 3650 -nodes -subj '/CN=localhost'
sed ':a;N;$!ba;s/\n/ /g' file
On February 26th 2018 the NVidia headers were removed from the FFmpeg source. A separate git repository was created to hold continuing work with these headers. At the moment these headers must be installed as well as FFmpeg from git to get access to nvenc and friends. (https://askubuntu.com/a/837320)
sudo apt-get install make git
mkdir $HOME/nv-codec-headers_build && cd $HOME/nv-codec-headers_build
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
cd nv-codec-headers
make && sudo make install
The nv-codec-headers will be automagically recognised (no extra ./configure options are needed) and nvenc will be successfully built.
To use the FFmpeg binary on another system:
apt install -y --no-install-recommends \
libavcodec-extra57 \
libavdevice57 \
libavfilter-extra6 \
libavformat57 \
libavresample3 \
libavutil55 \
libc6 \
libpostproc54 \
libsdl2-2.0-0 \
libswresample2 \
libswscale4 \
libfdk-aac1 \
nvidia-driver-440
ubuntu@ip-192-168-18-127:~$ cat /etc/apt/sources.list.d/cuda.list deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 / ubuntu@ip-192-168-18-127:~$ dpkg -l | grep -E -i "nvenc|cuda|nvidia" | grep ^ii ii cuda-drivers 418.67-1 amd64 CUDA Driver meta-package ii cuda-repo-ubuntu1804 10.1.243-1 amd64 cuda repository configuration files ii libnvidia-cfg1-418:amd64 418.67-0ubuntu1 amd64 NVIDIA binary OpenGL/GLX configuration library ii libnvidia-common-418 430.26-0ubuntu0.18.04.2 all Transitional package for libnvidia-common-430 ii libnvidia-common-430 430.26-0ubuntu0.18.04.2 all Shared files used by the NVIDIA libraries ii libnvidia-compute-418:amd64 418.67-0ubuntu1 amd64 NVIDIA libcompute package ii libnvidia-decode-418:amd64 418.67-0ubuntu1 amd64 NVIDIA Video Decoding runtime libraries ii libnvidia-encode-418:amd64 418.67-0ubuntu1 amd64 NVENC Video Encoding runtime library ii libnvidia-fbc1-418:amd64 418.67-0ubuntu1 amd64 NVIDIA OpenGL-based Framebuffer Capture runtime library ii libnvidia-gl-418:amd64 418.67-0ubuntu1 amd64 NVIDIA OpenGL/GLX/EGL/GLES GLVND libraries and Vulkan ICD ii libnvidia-ifr1-418:amd64 418.67-0ubuntu1 amd64 NVIDIA OpenGL-based Inband Frame Readback runtime library ii nvidia-compute-utils-418 418.67-0ubuntu1 amd64 NVIDIA compute utilities ii nvidia-dkms-418 418.67-0ubuntu1 amd64 NVIDIA DKMS package ii nvidia-driver-418 418.67-0ubuntu1 amd64 NVIDIA driver metapackage ii nvidia-kernel-common-418:amd64 430.26-0ubuntu0.18.04.2 amd64 Transitional package for nvidia-kernel-common-430 ii nvidia-kernel-common-430 430.26-0ubuntu0.18.04.2 amd64 Shared files used with the kernel module ii nvidia-kernel-source-418 418.67-0ubuntu1 amd64 NVIDIA kernel source package ii nvidia-modprobe 418.87.01-0ubuntu1 amd64 Load the NVIDIA kernel driver and create device files ii nvidia-prime 0.8.8.2 all Tools to enable NVIDIA's Prime ii nvidia-settings 418.87.01-0ubuntu1 amd64 Tool for configuring the NVIDIA graphics driver ii nvidia-utils-418 418.67-0ubuntu1 amd64 NVIDIA driver support binaries ii xserver-xorg-video-nvidia-418 418.67-0ubuntu1 amd64 NVIDIA binary Xorg driver
https://gist.github.com/calebhailey/8a30a00c6aadfebf7f767444f0a3df49
https://github.com/sensu/sensu-extensions-occurrences
A-Za-z0-9- ↩︎