Category: Bash / Terminal / Scripts

linux bash script – test if host is alive – internet connection test script – uptime test script

tested with: tested with/on: Static hostname: CentOS1.localdomain Operating System: CentOS Linux 7 (Core) Kernel: Linux 4.15.9 Architecture: x86-64 bash -version GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu) ping -V ping utility, iputils-s20160308 usage: /scripts/ cat /scripts/ #!/bin/bash # ping -c […]


i want to create a autostart script that starts whenever the server starts. mkdir /scripts vim /scripts/ #!/bin/bash echo “========= starting up docker service” systemctl start docker echo “========= starting up docker containers” docker start containername vim /scripts/ #!/bin/bash echo […]

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

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 […]


in a script you can specify to save output to a file with current date/time like: LOGFILE=/path/to/logfiles/$(date ‘+%Y-%m-%d’)_task.log echo “this script was run” >> $LOGFILE; to cleanup regularly is important in order to ensure the harddisk does not fill up. […]

Windows Batch CMD scripts – why endless loop?

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

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 […]


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


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 […]


vi; # 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 […]


usermod -s /bin/bash maria; # change login-shell of maria to bash usermod -s /bin/sh maria; # change login-shell of maria to sh # tested and works on debian8, suse12, centos7 usermod -s /bin/zsh maria; # change login-shell of maria to […]


 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 sheed

About: apt is a mainly-online-repository-based (“AppStore”) software installation – package management system used by Debian and Ubuntu. But – you can also manually download a package.deb and install it with dpkg -i package.deb. What might be confusing – it consists […]


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 […]


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 sheed – the future of Yum is Dnf

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 […]


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”; # […]