Benutzer-Werkzeuge

Webseiten-Werkzeuge


know-how:usefull_commands

world of powershell

$currentObject | Get-Member
  • Hilfe für Funktion
help Funktionsname
Help Funktionsname -example
foreach ( $currentObject in   Function_that_returns_multiple_results )
{
  $currentObject.Property 
}
String="vorname.nachname@domain"

String.split("@")[0] -> vorname.nachname

syslinux pxe menu password creation

openssl passwd -6 -salt 389asdkfj349 mypassword

awk - sum

grep and cut play  | awk '{sum += $1} END {print sum}' 

busybox - kill telnetd

#!/bin/bash


echo -e "IP1\nIP2\nIP3" | while read line ; do  ( echo "pid_telnet=\$(ps | grep -i telnetd | head -n 1 | awk '{ print \$1 }') ; kill -9 \$pid_telnet" ; sleep 1; ) | telnet  $line ; done

specific line from file

  • 4th line from file
sed :
$>sed -n 4p file.txt

head :
head -n 4 foo | tail -n 1

random line from file

  • single random entry from file
shuf -n 1 filename

runlevel systemd

  • „Targets“ keine „runlevel“ mehr
# systemctl get-default 
multi-user.target
# systemctl set-default  graphical.target
Removed /etc/systemd/system/default.target.
Created symlink /etc/systemd/system/default.target → /lib/systemd/system/graphical.target.

memtester check ram

Type the command "memtester 100 5" to test the memory. Replace "100" with the size, in megabytes, of the RAM installed on the computer. Replace "5" with the number of times you want to run the test.

Type the command "echo $?" to show the exit code when you see a command prompt again. If the output is "0" the memory is working properly. The other possible outcomes are:

ssh

  • Es konnte keine gemeinsame Krypto gefunden werden / Krypto manuell angeben:
zB:
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 user@target

apt / dpkg / debian / ubuntu based gpg trust add

  • wget quiet output to stdout | apt-key add gpg key from stdin
  • e.g. kali Repository (rolling release)
wget -q -O - https://archive.kali.org/archive-key.asc | apt-key add -

checkrestart for restarting necessary Services after update

  • check for apt-get install debian-goodies (contains checkrestart)
checkrestart | grep -i service | while read foo ; do  $foo && echo "$foo successfully restarted" ; done

APT-GET

  • Depends on the names of the repositories should work under debian and ubuntu / security upgrades check
apt-get --dry-run dist-upgrade | grep -i security
  • Install only security Updates limit Repositories to „security“
https://www.eidenschink.eu/2014/04/install-security-patches-command-line-debian-ubuntu.html

The trick is then to pass apt-get an option to read the sources from the created file like this:

apt-get upgrade -oDir::Etc::SourceList=/etc/apt/security.sources.list
  • Download ONLY not actual installing
apt-get --download-only dist-upgrade

Device wipe + ETA

# cat /dev/zero | pv > /dev/sdb 
4.83GiB 0:00:18 [ 156MiB/s] [>                                 ]  0% ETA 1:55:23>

DNS capture

tshark -f "udp port 53" -Y "(dns.qry.type == 1 or dns.qry.type==28) and dns.flags.response == 0"

insert line prefix

# If you want to edit the file in-place
sed -i -e 's/^/prefix/' file

Parse Squid time Format

perl -p -e 's/^([0-9]*)/"[".localtime($1)."]"/e' < squid.log >squid.log.time

Files from the last 7 days

find PATH -type f -ctime -7 

mail testmail

mail -a "From: <tester@test.com>" RECIPIENT_MAIL

Mutt

read Mailbox:
mutt -R -f /var/spool/mail/mailbackup/

send Mails:
echo "This is the message body" | mutt -a "/path/to/file.to.attach" -s "subject of message" -- recipient@domain.com

Mutt Bounce mails to:
l limit  messages to ~f (from) regex
http://perlcode.org/tutorials/mail/mutt-bounce.txt
Mutt Search : /

b - bounce message under cursor
t - tag message under cursor

;b - bounce tagged messages
;d - delete tagged messages


Proxy check URL w3m

http_proxy="http://IP:PORT" w3m http://URL

Vim

  • show non visible characters
:set list 
  • Disable auto mouse detection „i want to copy & paste like i used to“ (Debian 9)
vim /usr/share/vim/vim80/defaults.vim +69

" In many terminal emulators the mouse works just fine.  By enabling it you
" can position the cursor, Visually select and scroll with the mouse.
" if has('mouse')
"  set mouse=a
" endif
The delete ex command will work nicely.

:+,$d

ip add route/ip

Example:
192.168.24.0/24
ip route add 192.168.24.0/24 dev eth1 via 192.168.23.13 

IP-add/remove:
/sbin/ip addr add 10.1.1.1/24 brd + dev bond0
/sbin/ip addr del 10.1.1.1/24 dev bond0

git basics

-git status
-git diff 

Commit all changes
GIT_AUTHOR_NAME=cc GIT_AUTHOR_EMAIL=MAIL git commit -a 

Single File: 
GIT_AUTHOR_NAME=cc GIT_AUTHOR_EMAIL=MAIL git commit PATH_TO_FILE 

Command timeouts

timeout 20s 

Check latency with hping3

hping3 -p 80 -c 2 -S www.google.ca 

Bind dynmaic zones

server:/etc/bind/zones# rndc freeze zone 
server:/etc/bind/zones# vim zone
server:/etc/bind/zones# rndc thaw zone

MySQL

Repair MYISAM database:

 myisamchk --silent --force --fast --update-state --key_buffer_size=64M --sort_buffer_size=64M --read_buffer_size=1M --write_buffer_size=1M /path/to/datadir/*/*.MYI
 
Easy safe repair:
 myisamchk -r -q tbl_name 

Change database password for  User:
mysql> update user set password=PASSWORD("NEW-PASSWORD-HERE") where User='USER';

Solve umlaut troubles mysql:
http://blog.koehntopp.de/archives/3189-FAQ-Mein-mysqldump-zerstoert-meine-Umlaute.html
 
 Grant ACCESS:         
 GRANT ALL PRIVILEGES ON `testuser\_%` . * TO 'testuser'@'localhost';  

 MySQL Revoke u. Grant:
mysql> revoke  Trigger ON *.* from 'testdb'@'%';
Query OK, 0 rows affected (0.43 sec)

mysql> GRANT Trigger ON testdb.* to 'project'@'%';
Query OK, 0 rows affected (0.16 sec)

Tablenames case insensitive:
This depends on lower_case_table_names system variable in mysql.

Code:

mysql> SHOW GLOBAL VARIABLES LIKE 'lower_case_table_names';

If set to 0, table names are stored as specified and comparisons are case sensitive. If set to 1, table names are stored in lowercase on disk and comparisons are not case sensitive. If set to 2, table names are stored as given but compared in lowercase.

The default value is 0 on unix, 1 on windows and 2 on mac.

You can change this by specifying the option while starting mysqld (--lower-case-table-names=2 )

Change data type from column:
ALTER TABLE <table_name> MODIFY <col_name> VARCHAR(65536)

Get processlist:
database information_schema -> table processlist

If you use MySQL 5.1.7 or newer, you can use the PROCESSLIST table in the INFORMATION_SCHEMA. So you can query it with ordinary SELECT queries and apply filtering conditions in a WHERE clause.

This feature is not implemented in MySQL 5.0 and prior.


MySQL one line kill if TIME > xx
for count in $(echo "use information_schema; select ID from processlist where TIME>0" | mysql  --skip-column-names );  do echo "kill $count" | mysql; done

MySQL one line kill old:
for count in $(echo "show processlist" | mysql | awk '{ print $1 }'); do echo "kill $count" | mysql; done

MySQL determine database type:
http://stackoverflow.com/questions/1638070/how-can-i-determine-type-of-mysql-database-whether-it-is-innodb-or-myisam
show table status

Overcome ARG_MAX limit

find . -name '*.???.gz' -print0 | xargs -0 rm -f

OpenSSL

Create rsa key:
openssl genrsa -out privkey.pem 2048 

Create CSR:
openssl req -new -key privkey.pem -out cert.csr

Read CSR:
openssl req -in FILE.csr -text -noout 

Create Key and CSR:
openssl req -new -newkey rsa:2048 -nodes -keyout FILENAME.key -out FILENAME.csr

Public Key encryption
openssl rsautl -certin -encrypt -inkey publickey.pem -in foho -out encrypted.txt

SELF signed all in one:
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -sha512


pkcs12 create:
openssl pkcs12 -export -in name-cert.pem -inkey private/name-key.pem -certfile cacert.pem -name "[friendly name]" -out name-cert.p12


CA Zertfifikat neu auststellen mit sha256 - Achtung Zeit muss auf die Minute genau stimmen/Serial muss auch stimmen :
openssl x509  -in ca.crt -CA ca-kombo.crt -set_serial 0xBB0844165013F013 -CAkey ca.key  -out ca-new -days 7200 -sha256

Überprüfen ob Zertifikat von bestimmter CA ausgestellt wurde:
$ openssl verify -verbose -CAfile cacert.pem  server.crt
server.crt: OK

Überprüfen ob CRL von bestimmter CA unterschrieben wurde und ok ist:
openssl crl -verify -CAfile ca.crt -in crl.pem  -noout
verify OK


Fingerprint anzeigen sha1 oder sha256:
openssl x509 -in cert.crt -noout -sha256 -fingerprint
openssl x509 -in cert.crt -noout -sha1 -fingerprint

Bash

for i in *.ENDING; do command < $i 2>&1 | grep -qi 'uninitial' && echo $i; done

strlen:
echo ${#PATH} 

redirect stderr to stdout:
echo "fooo" 2>&1


Bash read file per line:
 while read test ; do echo $test ; done < test
Bash c like for loop:
for ((i=0; i<10 ; i++)) ; do echo $i; done

cat file | xargs -I{} echo {}
or:

for line in (< /path/to/file); do
    echo "Line: $line"
done


https://stackoverflow.com/questions/17368067/length-of-string-in-bash

you could even have a look at stored chars:

myvar='Généralités'
chrlen=${#myvar}
oLang=$LANG oLcAll=$LC_ALL
LANG=C LC_ALL=C
bytlen=${#myvar}
printf -v myreal "%q" "$myvar"
LANG=$oLang LC_ALL=$oLcAll
printf "%s has %d chars, %d bytes: (%s).\n" "${myvar}" $chrlen $bytlen "$myreal"

will answer:

Généralités has 11 chars, 14 bytes: ($'G\303\251n\303\251ralit\303\251s').

Nota: According to Isabell Cowan's comment, I've added setting to $LC_ALL along with $LANG.
Length of an argument

Argument work same as regular variables

strLen()


   
   https://www.thegeekstuff.com/2010/07/bash-string-manipulation/

Bash String Manipulation Examples – Length, Substring, Find and Replace
by SASIKALAon JULY 23, 2010

In bash shell, when you use a dollar sign followed by a variable name, shell expands the variable with its value. This feature of shell is called parameter expansion.

But parameter expansion has numerous other forms which allow you to expand a parameter and modify the value or substitute other values in the expansion process. In this article, let us review how to use the parameter expansion concept for string manipulation operations.

This article is part of the on-going bash tutorial series. Refer to our earlier article on bash { } expansion.
1. Identify String Length inside Bash Shell Script

${#string}

The above format is used to get the length of the given bash variable.

$ cat len.sh
#! /bin/bash

var="Welcome to the geekstuff"

echo ${#var}

$ ./len.sh
24

To understand more about bash variables, read 6 Practical Bash Global and Local Variable Examples.
2. Extract a Substring from a Variable inside Bash Shell Script

Bash provides a way to extract a substring from a string. The following example expains how to parse n characters starting from a particular position.

${string:position}

Extract substring from $string at $position

${string:position:length}

Extract $length of characters substring from $string starting from $position. In the below example, first echo statement returns the substring starting from 15th position. Second echo statement returns the 4 characters starting from 15th position. Length must be the number greater than or equal to zero.

$ cat substr.sh
#! /bin/bash

var="Welcome to the geekstuff"

echo ${var:15}
echo ${var:15:4}

$ ./substr.sh
geekstuff
geek

Also, refer to our earlier article to understand more about $*, $@, $#, $$, $!, $?, $-, $_ bash special parameters.
3. Shortest Substring Match

Following syntax deletes the shortest match of $substring from front of $string

${string#substring}

Following syntax deletes the shortest match of $substring from back of $string

${string%substring}

Following sample shell script explains the above two shortest substring match concepts.

$ cat shortest.sh
#! /bin/bash

filename="bash.string.txt"

echo ${filename#*.}
echo ${filename%.*}

$ ./shortest.sh
After deletion of shortest match from front: string.txt
After deletion of shortest match from back: bash.string

In the first echo statement substring ‘*.’ matches the characters and a dot, and # strips from the front of the string, so it strips the substring “bash.” from the variable called filename. In second echo statement substring ‘.*’ matches the substring starts with dot, and % strips from back of the string, so it deletes the substring ‘.txt’
4. Longest Substring Match

Following syntax deletes the longest match of $substring from front of $string

${string##substring}

Following syntax deletes the longest match of $substring from back of $string

${string%%substring}

Following sample shell script explains the above two longest substring match concepts.

$ cat longest.sh
#! /bin/bash

filename="bash.string.txt"

echo "After deletion of longest match from front:" ${filename##*.}
echo "After deletion of longest match from back:" ${filename%%.*}

$ ./longest.sh
After deletion of longest match from front: txt
After deletion of longest match from back: bash

In the above example, ##*. strips longest match for ‘*.’ which matches “bash.string.” so after striping this, it prints the remaining txt. And %%.* strips the longest match for .* from back which matches “.string.txt”, after striping  it returns “bash”.
5. Find and Replace String Values inside Bash Shell Script
Replace only first match

${string/pattern/replacement}

It matches the pattern in the variable $string, and replace only the first match of the pattern with the replacement.

$ cat firstmatch.sh
#! /bin/bash

filename="bash.string.txt"

echo "After Replacement:" ${filename/str*./operations.}

$ ./firstmatch.sh
After Replacement: bash.operations.txt

Replace all the matches

${string//pattern/replacement}

It replaces all the matches of pattern with replacement.

$ cat allmatch.sh
#! /bin/bash

filename="Path of the bash is /bin/bash"

echo "After Replacement:" ${filename//bash/sh}

$ ./allmatch.sh
After Replacement: Path of the sh is /bin/sh

Taking about find and replace, refer to our earlier articles – sed substitute examples and Vim find and replace.
Replace beginning and end

${string/#pattern/replacement}

Following syntax replaces with the replacement string, only when the pattern matches beginning of the $string.

${string/%pattern/replacement}

Following syntax replaces with the replacement string, only when the pattern matches at the end of the given $string.

$ cat posmatch.sh
#! /bin/bash

filename="/root/admin/monitoring/process.sh"

echo "Replaced at the beginning:" ${filename/#\/root/\/tmp}
echo "Replaced at the end": ${filename/%.*/.ksh}

$ ./posmatch.sh
Replaced at the beginning: /tmp/admin/monitoring/process.sh
Replaced at the end: /root/admin/monitoring/process.ksh

Recommended Reading


https://stackoverflow.com/questions/3173131/redirect-copy-of-stdout-to-log-file-from-within-bash-script-itself
redirect output of script itself to file


#!/usr/bin/env bash

# Redirect stdout ( > ) into a named pipe ( >() ) running "tee"
exec > >(tee -i logfile.txt)

# Without this, only stdout would be captured - i.e. your
# log file would not contain any error messages.
# SEE (and upvote) the answer by Adam Spiers, which keeps STDERR
# as a separate stream - I did not want to steal from him by simply
# adding his answer to mine.
exec 2>&1

echo "foo"
echo "bar" >&2

RAM info

dmidecode --type 17

Ubuntu version

lsb_release -a

Traffic shaping

Show:
tc class ls dev DEVICE

Gratious ARP

iputils-arping
arping -U -I eth0 IP/Adresse

Socat

socat - unix:socketfilename

Screen

SHARE teilen/detachen:
strg+A :multiuser on ->"server"
screen -x ->client 
Ctrl+A+D for detaching the screen 
  • Screen resume nicht möglich da er es als „attached“ betrachtet
# screen -r 16894
There is a screen on:
	16894.pts-0.backup	(09/01/20 11:17:52)	(Attached)
There is no screen to be resumed matching 16894.
# screen -r -d 16894

Associated Clients hostapd/wpad

iw dev wlan0 station dump

Disassociate Client hostapd/wpad

The default wpad-mini package does provide the disassociate command but not the all_sta. So get the list of associated clients on card wlan1 with iwinfo wlan1 assoclist, select a MAC address and then "kick" it with (for example):

hostapd_cli disassociate -i wlan1 01:23:45:67:89:AB

Considering a client usually tries to reconnect when disconnected, this might just disconnect it for about 10s.
  • Mit iw getestet auf lede 17er Edition
  • Auf 4.19 Kernel (kali linux) probiert er nach ~20-30 Sekunden wieder einen reconnect
Usage:	iw [options] dev <devname> station del <MAC address> [subtype <subtype>] [reason-code <code>]

Remove the given station entry (use with caution!)
Example subtype values: 0xA (disassociation), 0xC (deauthentication)


-> iw dev wlan0 station del MAC-ADRESSE-HIER subtype 0xA

Harddisk shutdown

echo 1 > /sys/block/sdf/device/delete

Check tape

mt -f /dev/st0 status 
mt -f /dev/st0 rewind
mt -f "$TAPE_DEV" eject

postfix

list queue:
postqueue -p
flush queue:
postqueue -f 

Linux software mdadm

mdadm --assemble /dev/md0 --run /dev/sdb1 

Degraded raid1:
$ mdadm --create /dev/md0 -l raid1 -f -n 1 /dev/sda1

(Von Wiki Thomas Krenn: https://www.thomas-krenn.com/de/wiki/RAID_Controller#Software_RAID )
SDX1 hot remove:
root@ubuntumdraidtest:~# mdadm --manage /dev/mdN -r /dev/sdX1
mdadm: hot removed /dev/sdX1 from /dev/mdN

SDX1 add:
root@ubuntumdraidtest:~# mdadm --manage /dev/mdN -a /dev/sdX1
mdadm: added /dev/sdX1

Wenn degraded und status inactive e.g.

root@mrChief:/home/urnilxfgbez# mdadm --run /dev/md127
root@mrChief:/home/urnilxfgbez# cat /proc/mdstat 

Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] 
md127 : active (auto-read-only) raid1 sdb1[0]
      1953511936 blocks [2/1] [U_]
      bitmap: 0/15 pages [0KB], 65536KB chunk

VNC Viewer Hextile

xvncviewer -encoding Hextile 

NIC blink

ethtool -p ethx

ARP flux

prevent arp replies on different NICs
zB: echo 1 > /proc/sys/net/ipv4/conf/all/arp_filter

LDAP queries

ldapsearch -h SERVER -D 'CN=Administrator,CN=Users,DC=DOMAIN,DC=local' -x -W -b 'DC=DOMAIN,DC=local' '(&(ATTRIBUTE=1)(objectCategory=Person))' dn ATTRIBUTE

Wget

download all files directory listening with ending .exe:
 wget -q -rl 1 -nd "http://PATH" -A*.exe

Ubuntu

Change keyboard layout:
sudo dpkg-reconfigure console-setup

Winbind

wbinfo - Query information from winbind daemon

Domain join linux server

root# net ads join -UAdministrator%password
http://www.samba.org/samba/docs/man/Samba-HOWTO-Collection/domain-member.html

Load Kernel module

make kernel module loadable
depmod -a  program to generate modules.dep and map filesi

less

http://www.thegeekstuff.com/2010/02/unix-less-command-10-tips-for-effective-navigation/

& -> matches only

:n – go to the next file.
:p – go to the previous file.
G – go to the end of file
g – go to the start of file

ddrescue

Disk to image

In this scenario the disk drive /dev/sdb is about to fail and we want to create an exact copy in the form of an image.

First, copy every block without read error and log the errors to /root/rescue.log.
Note
This requires at least as much disk space as the size of the failing disk drive.
root #ddrescue -f -n /dev/sdb /root/sdb_rescue.img /root/rescue.log

-f 
    Force ddrescue to run even if the destination file already exists.
-n 
    Skip the splitting phase to avoid spending a lot of time trying to rescue the most difficult parts of a file.

Second, copy only the bad blocks and try 3 times to read from the source before giving up:
root #ddrescue -d -f -r3 /dev/sdb /root/sdb_rescue.img /root/rescue.log

-d
    Use direct access to the drive and skip any cache.
-rN
    Try N times to rescue the block.

Now the image can be mounted as loop device and the file system checked for corruption.
Note
It can be helpful to not retry at all in cases where the USB controller disconnects the drive if certain blocks are read. Here you may want to skip any errored block.

lvm

  • Empfehlung falls lvm_volume ROOT von einer virtuellen Maschine über kvm - vorher herunterfahren!
  • Verkleinert direkt darunter liegendes Filesystem + LVM - getestet auf Debian stretch
# lvresize --size 150G --resizefs /dev/mapper/lvm_volume
  • LVM Resize - erweitern:
lvresize -L+500G /dev/mapper/foo-lvm
  • LVM Logical Volume anlegen:
lvcreate -n name-lvm  -L500G volume-group
  • LVM Snapshots:
lvcreate -L <LV size> -s -n <snapshot name> /dev/<VG name>/<LV name>
lvremove /dev/<VG name>/<snapshot name>
  • LVM Snapshots - Beispiele um an Filesystem zu kommen (offset mount - 2048*512, oder kpartx)
root@mrGodfather:/mnt# lvcreate  -L200M -s -n guest-mrscanner-root-snapshot /dev/mapper/mrGodfather-guest--mrscanner--root 
  Logical volume "guest-mrscanner-root-snapshot" created.
root@mrGodfather:/mnt# kpartx -av /dev/mapper/mrGodfather-guest--mrscanner--root--snapshot
add map mrGodfather-guest--mrscanner--root--snapshot1 (253:22): 0 136312832 linear 253:21 2048
root@mrGodfather:/mnt# mount -o ro /dev/mapper/mrGodfather-guest--mrscanner--root--snapshot1 /mnt/tmp
root@mrGodfather:/mnt# ls -al /mnt/tmp/
total 2097308
drwxr-xr-x  22 root root       4096 Jul 24 06:39 .
drwxr-xr-x   5 root root       4096 Mar 10  2018 ..
drwxr-xr-x   2 root root       4096 Jul  5 06:53 bin
drwxr-xr-x   3 root root       4096 Jul 25 06:47 boot
drwxr-xr-x   2 root root       4096 Mar 23  2016 dev
drwxr-xr-x 111 root root      12288 Aug  1 06:08 etc
drwxr-xr-x   2 root root       4096 Mar 23  2016 home
lrwxrwxrwx   1 root root         33 Jul 24 06:39 initrd.img -> boot/initrd.img-4.15.0-55-generic
lrwxrwxrwx   1 root root         33 Jul 24 06:39 initrd.img.old -> boot/initrd.img-4.15.0-54-generic
drwxr-xr-x  20 root root       4096 May 21 12:18 lib
drwxr-xr-x   2 root root       4096 May 21 11:59 lib64
drwx------   2 root root      16384 Mar  8  2016 lost+found
drwxr-xr-x   3 root root       4096 Mar  8  2016 media
drwxr-xr-x   2 root root       4096 Jun 25  2018 mnt
drwxr-xr-x   2 root root       4096 Feb 18  2016 opt
dr-xr-xr-x   2 root root       4096 Mar 23  2016 proc
drwx------   7 root root       4096 Aug  9 01:12 root
drwxr-xr-x   3 root root       4096 Oct 19  2016 run
drwxr-xr-x   2 root root      12288 May 21 12:21 sbin
drwxr-xr-x   2 root root       4096 Feb 18  2016 srv
-rw-rw----   1 root root 2147483648 Mar 18  2016 swap.img
dr-xr-xr-x   2 root root       4096 Mar 23  2016 sys
drwxrwxrwt  11 root root      40960 Aug 13 09:45 tmp
drwxr-xr-x  10 root root       4096 Mar  8  2016 usr
drwxr-xr-x  13 root root       4096 Oct 19  2016 var
lrwxrwxrwx   1 root root         30 Jul 24 06:39 vmlinuz -> boot/vmlinuz-4.15.0-55-generic
lrwxrwxrwx   1 root root         30 Jul 24 06:39 vmlinuz.old -> boot/vmlinuz-4.15.0-54-generic
root@mrGodfather:/mnt# umount /mnt/tmp/
root@mrGodfather:/mnt# kpartx -dv /dev/mapper/mrGodfather-guest--mrscanner--root--snapshot
del devmap : mrGodfather-guest--mrscanner--root--snapshot1
root@mrGodfather:/mnt# fdisk /dev/mapper/mrGodfather-guest--mrscanner--root--snapshot

Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/mapper/mrGodfather-guest--mrscanner--root--snapshot: 70 GiB, 75161927680 bytes, 146800640 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xe7f8c045

Device                                                         Boot Start       End   Sectors Size Id Type
/dev/mapper/mrGodfather-guest--mrscanner--root--snapshot-part1       2048 136314879 136312832  65G 83 Linux

Command (m for help): q

root@mrGodfather:/mnt# mount -o ro,offset=1048576 /dev/mapper/mrGodfather-guest--mrscanner--root--snapshot /mnt/tmp
root@mrGodfather:/mnt# ls -al /mnt/tmp/
total 2097308
drwxr-xr-x  22 root root       4096 Jul 24 06:39 .
drwxr-xr-x   5 root root       4096 Mar 10  2018 ..
drwxr-xr-x   2 root root       4096 Jul  5 06:53 bin
drwxr-xr-x   3 root root       4096 Jul 25 06:47 boot
drwxr-xr-x   2 root root       4096 Mar 23  2016 dev
drwxr-xr-x 111 root root      12288 Aug  1 06:08 etc
drwxr-xr-x   2 root root       4096 Mar 23  2016 home
lrwxrwxrwx   1 root root         33 Jul 24 06:39 initrd.img -> boot/initrd.img-4.15.0-55-generic
lrwxrwxrwx   1 root root         33 Jul 24 06:39 initrd.img.old -> boot/initrd.img-4.15.0-54-generic
drwxr-xr-x  20 root root       4096 May 21 12:18 lib
drwxr-xr-x   2 root root       4096 May 21 11:59 lib64
drwx------   2 root root      16384 Mar  8  2016 lost+found
drwxr-xr-x   3 root root       4096 Mar  8  2016 media
drwxr-xr-x   2 root root       4096 Jun 25  2018 mnt
drwxr-xr-x   2 root root       4096 Feb 18  2016 opt
dr-xr-xr-x   2 root root       4096 Mar 23  2016 proc
drwx------   7 root root       4096 Aug  9 01:12 root
drwxr-xr-x   3 root root       4096 Oct 19  2016 run
drwxr-xr-x   2 root root      12288 May 21 12:21 sbin
drwxr-xr-x   2 root root       4096 Feb 18  2016 srv
-rw-rw----   1 root root 2147483648 Mar 18  2016 swap.img
dr-xr-xr-x   2 root root       4096 Mar 23  2016 sys
drwxrwxrwt  11 root root      40960 Aug 13 09:45 tmp
drwxr-xr-x  10 root root       4096 Mar  8  2016 usr
drwxr-xr-x  13 root root       4096 Oct 19  2016 var
lrwxrwxrwx   1 root root         30 Jul 24 06:39 vmlinuz -> boot/vmlinuz-4.15.0-55-generic
lrwxrwxrwx   1 root root         30 Jul 24 06:39 vmlinuz.old -> boot/vmlinuz-4.15.0-54-generic
root@mrGodfather:/mnt# umount /mnt/tmp/
root@mrGodfather:/mnt# lvremove /dev/mapper/mrGodfather-guest--mrscanner--root--snapshot 
Do you really want to remove active logical volume mrGodfather/guest-mrscanner-root-snapshot? [y/n]: y
  Logical volume "guest-mrscanner-root-snapshot" successfully removed

  • LVM anzeigen volume groups / logical volumes:
vgdisplay
vgs
lvs

PHP

  • Beispiel für eine „pipe“ in PHP bei Skriptaufruf
...
#!/usr/bin/php
<?php

#Pipe Username\n and Password\n to php
$auth_data = file("php://stdin");


if(count($auth_data) != 2)
{
	exit(1);
}



$USERNAME=trim($auth_data[0]);
$PASSWORD=trim($auth_data[1]);

...
You can use the GLOB_BRACE constant

    GLOB_BRACE - Expands {a,b,c} to match 'a', 'b', or 'c'

e.g.

$dirname = 'uploads/';
glob("$dirname*.{png,jpeg,jpg,gif}", GLOB_BRACE);

See: http://php.net/manual/en/function.glob.php

letsencrypt magic

  • apt-get install certbot
  • Hostname e.g. hostname.domain.at MUSS von extern über Port 80 für Challenge/Response zur Verfügung stehen
  • IP's lassen sich NICHT firewallen von let's encrypt - it's a feature :)
oot@firewall:/tmp# certbot certonly --webroot --webroot-path /var/www/letsencrypt/ -d hostname.domain.at
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): support@domain.at

-------------------------------------------------------------------------------
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v01.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A

-------------------------------------------------------------------------------
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: N
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for hostname.domain.at
Using the webroot path /var/www/letsencrypt for all unmatched domains.
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/hostname.domain.at/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/hostname.domain.at/privkey.pem
   Your cert will expire on 2019-03-19. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

root@firewall:/tmp# certbot certonly --webroot --webroot-path /var/www/letsencrypt/ -d hostname.domain.at
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Cert not yet due for renewal

You have an existing certificate that has exactly the same domains or certificate name you requested and isn't close to expiry.
(ref: /etc/letsencrypt/renewal/hostname.domain.at.conf)

What would you like to do?
-------------------------------------------------------------------------------
1: Keep the existing certificate for now
2: Renew & replace the cert (limit ~5 per 7 days)
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): c
Operation canceled. You may re-run the client.
root@firewall:/tmp# certbot renew --quiet --post-hook "service apache2 restart"
root@firewall:/tmp# echo $?
0
Cookies helfen bei der Bereitstellung von Inhalten. Diese Website verwendet Cookies. Mit der Nutzung der Website erklären Sie sich damit einverstanden, dass Cookies auf Ihrem Computer gespeichert werden. Außerdem bestätigen Sie, dass Sie unsere Datenschutzerklärung gelesen und verstanden haben. Wenn Sie nicht einverstanden sind, verlassen Sie die Website. Weitere Information
know-how/usefull_commands.txt · Zuletzt geändert: 2020/01/21 10:21 von cc