Skip to content

Category: Linux

bash script to clean up directories

#!/bin/bash
# Define the directory to search (you can change this to the desired directory)
DIR="/temp"

# Array of file extensions to delete
EXTENSIONS=("*.txt" "*.srt" "*.nzb" "*.sup" "*.ac3" "*.dts" "*.sample.*" "*.srr")

# Counters for deleted files and directories
deleted_files=0
deleted_directories=0

# Loop through the array and delete the files, counting each deletion
for EXT in "${EXTENSIONS[@]}"; do
    count=$(find "$DIR" -type f -name "$EXT" -print -delete | wc -l)
    deleted_files=$((deleted_files + count))
done

# Find and delete empty directories, counting each deletion
count=$(find "$DIR" -type d -empty -print -delete | wc -l)
deleted_directories=$((deleted_directories + count))

# Output the counts
echo "Deleted $deleted_files files with extensions ${EXTENSIONS[*]}."
echo "Deleted $deleted_directories empty directories."

For the most up-to-date version, follow the links below.

https://snippets.cacher.io/snippet/b554e570d8ffc0431ad9

https://gist.github.com/xavier-hernandez/f4979b4ce174068ce5428a26ae08be32

Leave a Comment

traefik v3 example with uptime-kuma

Here is an example of Traefik, using Uptime-Kuma as an example with a domain for it plus using letsencrypt to secure the domain. We also redirect HTTP to HTTPS.

The Traefik dashboard is not secure, so please implement security or a firewall.

This is just an example.

version: "3"

services:
 uk1:
    image: louislam/uptime-kuma:1
    container_name: uk1
    volumes:
      - ./uk1-data:/app/data
    ports:
      - 3001:3001  # <Host Port>:<Container Port>
    restart: always
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.uk1.tls.certresolver=myresolver"
      - "traefik.http.routers.uk1-http.entrypoints=web"
      - "traefik.http.routers.uk1-http.rule=Host(`your_domain_here`)"
      - "traefik.http.routers.uk1-http.middlewares=uk1-https"
      - "traefik.http.middlewares.uk1-https.redirectscheme.scheme=https"
      - "traefik.http.routers.uk1.entrypoints=websecure"
      - "traefik.http.routers.uk1.rule=Host(`your_domain_here`)"
      - "traefik.http.routers.uk1.tls=true"
    depends_on:
      - traefik
 traefik:
  image: traefik:v3.0
  command:
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.myresolver.acme.httpchallenge=true"
      - "--certificatesresolvers.myresolver.acme.httpchallenge.entrypoint=web"
      - "--certificatesresolvers.myresolver.acme.email=your_email_address_here"
      - "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
  ports:
    - 80:80
    - 443:443
    - 8080:8080
  volumes:
    - "./letsencrypt:/letsencrypt"
    - /var/run/docker.sock:/var/run/docker.sock

https://gist.github.com/xavier-hernandez/48042d5cdb66a89ac5e92a92ecfeb7b5

Leave a Comment

Install dotnet core on Ubuntu 22.04

These are the steps I used to install dotnet core on Ubuntu 22.04, both the SDK and the runtime.

apt update
apt install -y apt-transport-https
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
apt update
apt install -y dotnet-sdk-7.0
apt update
apt install -y aspnetcore-runtime-7.0

To verify installation run the following commands. If the below doesn’t work try to open a new ssh session or terminal.

dotnet --list-runtimes

Microsoft.AspNetCore.App 7.0.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

dotnet --list-sdks

7.0.102 [/usr/share/dotnet/sdk]
root@srv4311:~# 

If you tried previously to install version 7.0 make sure you remove/purge the old version from the system. Something like below.

apt remove --purge dotnet-sdk-6.0 dotnet-runtime-6.0
apt auto-remove

Also maybe delete the .dotnet folder in your home directory.

Leave a Comment

GoAccess for Nginx Proxy Manager Logs

This docker container should work out of the box with Nginx Proxy Manager to parse proxy logs. The goaccess.conf has been configured to only access proxy logs and archived proxy logs. No fuss, no muss.

The docker image scans and includes files matching the following criteria: proxy-host-*_access.log.gz proxy-host-*_access.log

Currently using GoAccess version: 1.5.5

Unraid container is also available.

https://hub.docker.com/r/xavierh/goaccess-for-nginxproxymanager

Leave a Comment

Setting up Rocket.Chat with Mongo 4.2 via Docker

I could not find a docker-compose.yml example with rocket.chat using 4.2 so I pieced one together.

Also, some tips on these errors.

Error: $MONGO_OPLOG_URL must be set to the ‘local’ database of a Mongo replica set

MongoError: not master and slaveOk=false

Visit my Github repo for more information: https://github.com/xavier-hernandez/rocket.chat/

Leave a Comment

Network stopped working in Ubuntu 18.04

I had a Ubuntu VM that lost its ability to get an IP. I have no idea why but I finally found the issue and it seems that the interface name changed.

Maybe its a bug : https://bugs.launchpad.net/ubuntu/+source/netplan.io/+bug/1881832

So I found out that the network interface that was trying to do DHCP did not exist. You’ll find this in /etc/netplan/50-cloud-init.yaml . For some reason, it showed that my interface was enp1s0 but it wasn’t, it was enp3s0. So I modified the file and rebooted the server. Everything is fine now.

Leave a Comment

Duplicati on Ubuntu 16.04 – Headless

Install Mono
https://www.mono-project.com/download/stable/#download-lin-ubuntu

sudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
sudo apt install apt-transport-https ca-certificates
echo “deb https://download.mono-project.com/repo/ubuntu stable-xenial main” | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
sudo apt update

sudo apt install mono-devel

Install Duplicati
wget https://updates.duplicati.com/beta/duplicati_2.0.5.1-1_all.deb
apt install ./duplicati_2.0.5.1-1_all.deb

To Test
duplicati-server –webservice-interface=any –webservice-port=8200 –webservice-allowed-hostnames=*

Modify the following file, /etc/default/duplicati, to allow access for any IP
DAEMON_OPTS=”–webservice-interface=any –webservice-port=8200 –webservice-allowed-hostnames=*”

Add the following as /etc/systemd/system/duplicati.service
[Unit]
Description=Duplicati web-server
After=network.target

[Service]
EnvironmentFile=-/etc/default/duplicati
ExecStart=/usr/bin/duplicati-server $DAEMON_OPTS

[Install]
WantedBy=multi-user.target

To enable duplicati
systemctl enable duplicati

Check if the service is now running
systemctl status duplicati.service

If its not, try the following then check the status again
systemctl start duplicati.service

Leave a Comment

Pi-hole static DNS entry

This is more docker related but should be similar to just a plain jane install. You can add your static entries to the /etc/hosts file or you can add it the the dnsmasq.d configuration file.

Create a file under /etc/dnsmasq.d, something like myhosts.conf and add the following. Keep adding entries until your done.

host-record=hostname.com,192.168.1.1

Find your pi-hole dns configuration under /etc/dnsmasq.d. Open the file and add the following line to end of your the configuration file.

conf-file= /etc/dnsmasq.d/ myhosts .conf

Go back to the pi-hole GUI and restart the DNS under settings/system “restart DNS resolver”.

Leave a Comment

soyoustart – arm ufw error

If you get this error:

modprobe: ERROR: could not insert 'ip_tables': Exec format error
iptables v1.6.0: can't initialize iptables table `filter': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.

Run this:
$ wget http://last.public.ovh.hdaas.snap.mirrors.ovh.net/ubuntu/pool/main/l/linux-modules-armada375/linux-modules-armada375_4.5.2-4_armhf.deb
$ dpkg -i linux-modules-armada375_4.5.2-4_armhf.deb

Found on: https://www.lowendtalk.com/discussion/comment/2806769/#Comment_2806769

Leave a Comment

Reset Ubuntu password in Windows 10

I forgot my password to the Ubuntu app in Windows. Here is the way I reset it.

  • close the app if you have it open
  • open a command prompt as administrator, open ubuntu has root
    • ubuntu config –default-user root
  • you’ll be logged in as root, now change the password for your user name
    • passwd username
  • exit ubuntu
  • reset ubuntu back to your username
    • ubuntu config –default-user username
  • exit ubuntu
  • re-launch ubuntu

Got the steps here: https://askubuntu.com/questions/772050/reset-the-password-in-linux-bash-in-windows

Leave a Comment

CentOS 6 – Change System Language

I recently bought a server whose language was set to something other than English. Here is the way to change the language.

Run the following commands

 nano /etc/sysconfig/i18n

and replace with the following

LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"

Log out and log back in. You should see the change.

Leave a Comment

How To Determine Your Linux Version

To determine what version of linux you are running enter the following command.

CentOS / RedHat

cat /etc/fedora-release

Debian / Ubuntu

cat /etc/issue

or

lsb_release -a

Run the following command to determine if you are running a 32-bit or 64-bit version.

# uname -a
Leave a Comment