Category: Bash / Terminal / Scripts

19.04.2018

/scripts/update_server.sh apk update; apk upgrade –available; sync; https://alpinelinux.org/ https://en.wikipedia.org/wiki/Alpine_Linux About Alpine Linux is an independent, non-commercial, general purpose Linux distribution designed for power users who appreciate security, simplicity and resource efficiency. Small Alpine Linux is built around musl libc and […]

27.02.2018

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

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 sheed
06.06.2017

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

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

24.05.2017

What is yum? yum is used under CentOS7, Fedora, RedHat RHEL, Oracle). It’s written in python and it stands for “Yellowdog Updater, Modified”, as it was originally called “yup”, the package manager for Yellow Dog Linux. In addition to rpm […]

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

vim stresscpu.sh; # create new script file #!/bin/bash while true; do echo -n "+."; done; save and quit chmod u+x stresscpu.sh; # mark it runnable nohup stresscpu.sh & # run in background htop # streeeeeeessss! it is also a harddisk-stress […]

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 >  ————- \                             .       .  \                           / `.   .‘ “   […]

21.05.2017

uname -a; # tested with Linux debian 3.16.0-4-686-pae #1 SMP Debian 3.16.43-2 (2017-04-30) i686 GNU/Linux vim /scripts/partitions_overview.sh; # create new script #!/bin/bash PARTITIONS=/dev/sd* for f in $PARTITIONS do   echo "_______________________________________________________________________________"   blkid $f   hdparm -I $f | grep […]