On Thu, Jun 02, 2016 at 08:08:19PM +0200, Frans Haarman wrote:
> I got tired of typing hostname so came up with this little tweak. Now
> atleast I have some tab completion.
>
> Maybe useful for some ? Do you have a differnt approach ?
>
> Regards,
> Frans
>
>
>
> # cd /etc/interface/
> # ls -la
> total 12
> drwxr-xr-x 2 root wheel 512 Jun 2 19:51 .
> drwxr-xr-x 23 root wheel 1536 Jun 2 19:42 ..
> -rw-r--r-- 1 root wheel 144 Jun 2 19:47 .mklink
> lrwxr-xr-x 1 root wheel 21 Jun 2 19:47 bridge0 -> /etc/hostname.bridge0
> lrwxr-xr-x 1 root wheel 21 Jun 2 19:47 vether0 -> /etc/hostname.vether0
> lrwxr-xr-x 1 root wheel 23 Jun 2 19:47 vether247 ->
> /etc/hostname.vether247
> lrwxr-xr-x 1 root wheel 22 Jun 2 19:47 vlan2470 ->
> /etc/hostname.vlan2470
> lrwxr-xr-x 1 root wheel 18 Jun 2 19:47 vmx0 -> /etc/hostname.vmx0
> lrwxr-xr-x 1 root wheel 18 Jun 2 19:47 vmx1 -> /etc/hostname.vmx1
> #
>
> # cat .mklink
> #!/bin/sh
>
> interfaces=`ls -1 /etc |grep "hostname.*" | sed 's/hostname\.//g' `
> for int in $interfaces; do
> ln -s /etc/hostname.$int $int
> done
>
> # vi /etc/interface/
> bridge0 vether0 vether247 vlan2470 vmx0 vmx1
> # vi /etc/interface/v
> vether0 vether247 vlan2470 vmx0 vmx1
> # vi /etc/interface/vether
> vether0 vether247
> # vi /etc/interface/vether247
I do not think this script is very useful but on the subject matter
of shell scripting you need to learn about shell expansions and
substitutions:
Something like:
for i in /etc/hostname.*; do
ln -sf /etc.hostname.$i ${i#/etc/hostname.}
done
(untested)
-Otto