Category: Bash / Terminal / Scripts

Samba4 on CentOS7 in under 10min – add windows file sharing user script – security – from SMB 1.0 to 2.0 – anti ETERNALBLUE EXPLOIT update trouble – SID “username” is not in a valid format – pdb_getsampwnam (tdb) error fetching database – solved
19.04.2018

update: 2019-02: everything was fine… until you decided to update because of the EthernalBlue exploit THAT ALSO AFFECTS OPEN SOURCE IMPLEMENTATIONS OF SMB 1.0! (WTF!? WHY?), samba now miss behaves on Debian and CentOS. (scroll down for details) EternalBlue, sometimes […]

Windows Batch CMD scripts – why endless loop?
12.02.2018

sometimes the scripts that used to work perfectly well – suddenly start to miss behave – but you HAVE NOT altered them! look closely to the directory they reside in… maybe something in the dir has changed! make sure: your […]

linux bash bc – calculating with pi
27.01.2018

bc is cool, but it can not access shell variables directly, but you can pass them with <<< also there is no “pi” constant in bc that you could use in interactive mode. let one assume you would like to […]

14.07.2017

display ip and ip only of the host computer the script is running on. ifconfig eth0|grep inet| awk ‘{print $2}’ | cut -d: -f2 172.20.0.8 root@debian9:~# IP=$(ifconfig eth0|grep inet| awk ‘{print $2}’ | cut -d: -f2); echo $IP; 172.20.0.8

05.07.2017

there are some special automatically set environment variabels that might be interesting to know… echo $$; # PID of currently running shell echo $?; # return error code of last run program (before echo) echo $0; # return /path/and/way the […]

13.06.2017

vi countdown.sh; # create a new file with those lines #!/bin/bash COUNT=10 while (( COUNT > 0 )) do      echo -e “$COUNT \c”     sleep 1;     (( COUNT — )) done echo -e “\n\nWe have lift off!!” ESC […]

09.06.2017

# all these commands will modify /etc/passwd su – root # disable login for user usermod -s /usr/sbin/nologin username # change login-shell of username to bash usermod -s /bin/bash username # change login-shell of username to sh usermod -s /bin/sh […]

07.06.2017

 stat /etc/hosts   File: ‘/etc/hosts’   Size: 249             Blocks: 8          IO Block: 4096   regular file Device: 801h/2049d      Inode: 5506941     Links: 1 Access: (0644/-rw-r–r–)  Uid: (    0/    root)   Gid: (    0/    root) Access: 2017-06-06 15:37:06.896148382 +0200 Modify: 2017-06-06 15:37:04.728130437 +0200 Change: […]

apt cheat sheet
06.06.2017

about package.deb & apt Apt is a mainly-online-repository-based (“AppStore”) software installation & package management system used by Debian, Ubuntu and Mint (and other apt based distributions). But – it is possible to manually download a package.deb and install it with: […]

xargs
30.05.2017

one practical usage example of xargs: … to process every file that find found further # this would backup/pack all jpg files on your system into all.jpg.tar.gz find / -name “*.jpg” | xargs tar -czvf all.jpg.tar.gz # delete all jpg […]

24.05.2017

what is umask? umask defines what what access rights newly created files “are born”. we are all supposed to be created equal – but depending if you are a son of Rothchild, Rockefeller or born in Namibia – your previleges […]

Yum cheat sheet – the future of Yum is Dnf
24.05.2017

update: 2021-1 yum -> dnf hostnamectl; # tested on Virtualization: kvm Operating System: CentOS Linux 8 CPE OS Name: cpe:/o:centos:centos:8 Kernel: Linux 5.4.11 Architecture: x86-64 ll /usr/bin/yum -> dnf-3 all those yum commands still work with dnf (nice work!) DNF […]

23.05.2017

reboot [cc lang=”bash” escaped=”true” width=”600″] reboot; # simply reboots the system 😉 init 6; # does the same telinit 6; # shutdown -r now; # “standard” way shutdown -r +1 “the system is going to reboot in one minute”; # […]

22.05.2017

Table 4-1. Regular expression operators Operator Effect . Matches any single character. ? The preceding item is optional and will be matched, at most, once. * The preceding item will be matched zero or more times. + The preceding item […]

22.05.2017

cool apt-get install fortune cowsay; # will have to be installed first then you can let your dinosaur speak 😀  /usr/games/cowsay -f stegosaurus “Hello World”  _____________ < Hello World >  ————- \                             .       .  \                           / `.   .’ ”   […]

19.05.2017

these commands are equally valid, both commands add “content” to the end of file – if file does not exists it will be created. ls -l . /ect > listing.txt #send the output from ls -l to a file called […]