The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

Archive for the ‘bash’ Category

Some useful links on bash parameters: $1, $*, $@, quotes, etc.

Posted by jpluimers on 2016/06/22

Some notes with the links I found them:

Syntax Effective result
$* $1 $2 $3 … ${N}
$@ $1 $2 $3 … ${N}
"$*" "$1c$2c$3c…c${N}"
"$@" "$1" "$2" "$3" … "${N}"

–jeroen

Posted in bash, Development, Scripting, Software Development | Leave a Comment »

Aliases for tools removed from `net-tools` package – via: openSUSE Build Service

Posted by jpluimers on 2016/06/16

Since quite a few commands that you regularly see mentioned on the web have been removed from OpenSuSE net-tools, I’ve created a few bash aliases in /etc/bash.bashrc.local below.

Note the original commands are not good have been deprecated for years on various distros and therefore removed:

# stuff removed from net-tools
# see https://features.opensuse.org/317197 and https://build.opensuse.org/package/view_file/network:utilities/net-tools/net-tools.changes
## Because of changes on Thu Apr 10 12:33:41 UTC 2014
alias "arp=echo 'use \"ip neigh\" or \"ip -r neight\"' && ip neigh"
alias "ifconfig=echo 'use \"ip a\"' && ip a"
alias "netstat= echo 'use \"ss\" or \"ss -r\"' && ss"
alias "route=echo 'use \"ip r\"' && ip r"
## Because of changes on Sun Mar 29 00:41:21 UTC 2015
alias "ipmaddr=echo 'use \"ip maddr\"' && ip maddr"
alias "iptunnel=echo 'use \"ip tunnel\"' && ip tunnel"

Some bits of the net-tools change-log:

-------------------------------------------------------------------
Sun Mar 29 00:41:21 UTC 2015 - jengelh@inai.de
- ipmaddr and iptunnel are obsolete too, move them to subpackage.
(Superseded by `ip maddr` and `ip tunnel`)
- remove redundant %clean section
-------------------------------------------------------------------
Thu Apr 10 12:33:41 UTC 2014 - mmarek@suse.cz
- Move arp, ifconfig, netstat and route to a -deprecated subpackage
(fate#317196, fate#317197)
- Drop the rarp tool, which has been broken since kernel 2.3

Note that the -lntu parameter seems to be the same for both ss and netstat: [WayBackGet a list of Open Ports in Linux – Super User

–jeroen

via File net-tools.changes of Package net-tools – openSUSE Build Service.

Posted in *nix, *nix-tools, bash, bash, Development, Linux, openSuSE, Power User, Scripting, Software Development, SuSE Linux | Leave a Comment »

Use cURL to test local virtual hosts configuration – via: Stack Overflow

Posted by jpluimers on 2016/06/14

Quoting John Hart‘s brilliant answer:

Using --resolve leverages all of the normal logic that applies, but simply pretends the DNS lookup returned the data in your command-line option. It works just like /etc/hosts should.

Note --resolve takes a port number, so for HTTPS you would use

Https: curl --resolve 'yada.com:443:127.0.0.1' https://yada.com/something

Http: curl --resolve 'yada.com:80:127.0.0.1' http://yada.com/something

It requires curl 7.21.3 or higher (from the end of 2010). Which by now everybody should have.

–jeroen

more via: Set cURL to use local virtual hosts – Stack Overflow.

Posted in *nix, bash, cURL, Development, Power User, Scripting, Software Development | Leave a Comment »

network – How can I release and renew my DHCP lease from Terminal? – Ask Different

Posted by jpluimers on 2016/06/07

Via the answer below I created the renew alias. I already had the first two aliases.

alias route-and-ipaddresses="netstat -nr | grep 'Internet\|Gateway\|default' && echo && ifconfig | grep '\: flags\|inet\|inet6' && echo more detailed info through ifconfig and netstat -nr"

alias whatismyip="curl http://whatismyip.akamai.com && echo"

alias renew_dhcp="sudo ipconfig set en0 DHCP && echo waiting 10 seconds for DHCP lease to be obtained && sleep 10 && route-and-ipaddresses && whatismyip"

–jeroen

via: network – How can I release and renew my DHCP lease from Terminal? – Ask Different.

Posted in Apple, bash, Development, Mac, Mac OS X / OS X / MacOS, Mac OS X 10.6 Snow Leopard, MacBook, MacBook Retina, MacBook-Air, MacBook-Pro, MacMini, OS X 10.10 Yosemite, OS X 10.8 Mountain Lion, OS X 10.9 Mavericks, Power User, Scripting, Software Development | Leave a Comment »

bash – How do I find all of the symlinks in a directory tree? – Stack Overflow

Posted by jpluimers on 2016/06/01

I needed to find the symlinks in /etc pointing to directories and know both the name and place they point to.

revue:~ # ls -al `find -L /etc/ -xtype l -type d`
find: ‘/etc/ssh/broken/ssh_host_dsa_key’: Too many levels of symbolic links
find: ‘/etc/ssh/broken/ssh_host_ecdsa_key’: Too many levels of symbolic links
find: ‘/etc/ssh/broken/ssh_host_key’: Too many levels of symbolic links
find: ‘/etc/ssh/ssh_host_ecdsa_key’: Too many levels of symbolic links
find: ‘/etc/ssh/ssh_host_dsa_key’: Too many levels of symbolic links
find: ‘/etc/ssh/ssh_host_key’: Too many levels of symbolic links
lrwxrwxrwx 1 root root 19 May  7 15:43 /etc/apparmor.d/cache -> /var/cache/apparmor
lrwxrwxrwx 1 root root  6 Sep 28  2014 /etc/rc.d -> init.d
lrwxrwxrwx 1 root root 26 May 23 13:50 /etc/squid/errors -> /usr/share/squid/errors/de
lrwxrwxrwx 1 root root 28 Mar 25 22:07 /etc/ssl/certs -> /var/lib/ca-certificates/pem
lrwxrwxrwx 1 root root 18 Apr 30 14:20 /etc/xdg/systemd/user -> ../../systemd/user

–jeroen

via: bash – How do I find all of the symlinks in a directory tree? – Stack Overflow.

Posted in *nix, *nix-tools, bash, bash, Development, Linux, openSuSE, Power User, Scripting, Software Development, SuSE Linux | Leave a Comment »

domain name system – How to test DNS glue record? – Server Fault

Posted by jpluimers on 2016/05/26

Thanks Adrian W for providing the below example in your answer about obtaining GLUE record information for a domain.

It is an excellent showcase for the $IFS Internal Field Separator available in any nx shell.

In this case it is used to get the TLD (top-level domain) from the domain name specified at the command-line.

After that, it obtains the name servers for that TLD, and queries the glue records there, both using dig.

Here is a little shell script which implements Alnitak’s answer:

#!/bin/sh
S=${IFS}
IFS=.
for P in $1; do
  TLD=${P}
done
IFS=${S}

echo "TLD: ${TLD}"
DNSLIST=$(dig +short ${TLD}. NS)
for DNS in ${DNSLIST}; do
  echo "Checking ${DNS}"
  dig +norec +nocomments +noquestion +nostats +nocmd @${DNS} $1 NS
done

Pass the name of the domain as parameter:

./checkgluerecords.sh example.org

–jeroen

via domain name system – How to test DNS glue record? – Server Fault.

Posted in *nix, Apple, bash, Development, DNS, Linux, Mac, Mac OS X / OS X / MacOS, Mac OS X 10.4 Tiger, Mac OS X 10.5 Leopard, Mac OS X 10.6 Snow Leopard, Mac OS X 10.7 Lion, openSuSE, OS X 10.10 Yosemite, OS X 10.8 Mountain Lion, OS X 10.9 Mavericks, Power User, Scripting, Software Development, SuSE Linux | Leave a Comment »

Cygwin first run and a few aliases

Posted by jpluimers on 2016/04/06

Cygwin first run looks like this:

Copying skeleton files.
These files are for the users to personalise their cygwin experience.

They will never be overwritten nor automatically updated.

'./.bashrc' -> '/home/jeroenp//.bashrc'
'./.bash_profile' -> '/home/jeroenp//.bash_profile'
'./.inputrc' -> '/home/jeroenp//.inputrc'
'./.profile' -> '/home/jeroenp//.profile'

jeroenp@msmxp ~
$

It will copy some default files to your profile so you can modify them.

Since Cygwin will run ~/.bash_profile on logon, and that in turn starts ~/.bashrc (see below), I’ve modified the latter to run ~/.bash_aliases and bring those a bit in sync with my regular Mac machine:


# New user-defined bash aliases file
# Is executed from a modified .bashrc file
# .bashrc is executed from .bash_profile on cygwin
# on other systems, see http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html
## This is the portion in .bashrc you need to edit in cygwin to enable .bash_aliases:
## Aliases
##
## Some people use a different file for aliases
## if [ -f "${HOME}/.bash_aliases" ]; then
## source "${HOME}/.bash_aliases"
## fi
alias ls-8601='ls -l -T'
alias ls-full-8601='ls -l –time-style=full-iso'
# octal file modes through http://stackoverflow.com/questions/1795976/can-the-unix-list-command-ls-output-numerical-chmod-permissions
alias lsmod='ls -al|awk '\''{k=0;s=0;for(i=0;i<=8;i++){;k+=((substr($1,i+2,1)~/[rwxst]/)*2^(8-i));};j=4;for(i=4;i<=10;i+=3){;s+=((substr($1,i,1)~/[stST]/)*j);j/=2;};if(k){;printf("%0o%0o ",s,k);};print;}'\'''
# silence the progress meter on Cygwin with -sS via http://stackoverflow.com/questions/7373752/how-do-i-get-curl-to-not-show-the-progress-bar
alias whatismyip='curl -sS http://whatismyip.akamai.com && echo'

view raw

.bash_aliases

hosted with ❤ by GitHub

cURL has some idiosyncrasies, for instance Cygwin shows the progress meter by default, but Mac OS X does not. I wanted to disable the cURL progress meter and you heed -sS for that.

ls doesn’t show you octal file modes by default, but chown and umask use them, so I’ve got the lsmod alias through stack-overflow.

Bash initialisation

Getting your bash initialisation right can be tough. There are lengthy discussions about which .bash* files run under what circumstances:

–jeroen

Posted in bash, Development, Scripting, Software Development | Leave a Comment »

rsync as diff – compare files in two directory on remote server using unix – Stack Overflow

Posted by jpluimers on 2016/03/01

Too bad the accepted answer forgets about deleted files.

Use one of these to compare (but not sync) two directory trees.

For size-only comparision:

rsync -n -avr --size-only --delete /abc/home/sample1/ server2:/abc/home/sample2/

If you want to compare both contents and size:

rsync -n -avrc --delete /abc/home/sample1/ server2:/abc/home/sample2/

–jeroen

via: diff – compare files in two directory on remote server using unix – Stack Overflow.

Posted in *nix, bash, Development, Power User, rsync, Scripting, Software Development | Leave a Comment »

Bash Coding Style · drwetter/testssl.sh Wiki

Posted by jpluimers on 2016/01/31

Awesome read on bash Coding Style · drwetter/testssl.sh Wiki

Posted in bash, Development, Scripting, Software Development | Leave a Comment »

Getting your public IP address from the command-line

Posted by jpluimers on 2016/01/13

Many sites giving your public IP address return a web page with a bloat of html. From the command-line, you are usually only interested in the IP-address itself. Few services return exactly that.

Below are command-line examples to provide the public IP address mostly from a *nix perspective. Usually you can get similar commands to work with Windows binaries for wget and Windows binaries for curl.

In the end, I’ve opted for commands in this format, as I think akamai will last longer than the other sites (but does not include an end-of-line in the http result hence the echo on Mac/*nix):

I’ve not tried aria2 yet, but might provide commands for that in the future.

These are the Linux permutations for akamai:

curl whatismyip.akamai.com && echo
curl ipv4.whatismyip.akamai.com && echo
curl ipv6.whatismyip.akamai.com && echo
curl ipv4.whatismyip.akamai.com && echo && curl ipv6.whatismyip.akamai.com && echo

The last two are convenient when you have both IPv4 and IPv6 configured on “the outside”.

You can replace curl with wget -q -O – (which outputs to stdout) for each command. You can even ommit the http:// (as that is the default protocol for both curl and wget).

Read the rest of this entry »

Posted in *nix, *nix-tools, Apple, bash, bash, Batch-Files, cURL, Development, Linux, Mac, Mac OS X / OS X / MacOS, Mac OS X 10.4 Tiger, Mac OS X 10.5 Leopard, Mac OS X 10.6 Snow Leopard, Mac OS X 10.7 Lion, MacBook, MacBook Retina, MacBook-Air, MacBook-Pro, MacMini, OS X 10.10 Yosemite, OS X 10.8 Mountain Lion, OS X 10.9 Mavericks, Power User, Scripting, Software Development, SuSE Linux, wget | Leave a Comment »