Unix Shell - Re: sourced files filename

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > January 2006 > Re: sourced files filename





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: sourced files filename
none

2006-01-29, 9:31 pm

Wow, almost 3 years later!

ok, Bash 3.0+ now has a new variable:
$BASH_SOURCE

I have all my servers ipaddress info for routers, mail servers, samba
servers, dns, dhcp, etc hard coded into ifcfg type files, called
"router.ifcfg", etc.
I just create a symbolic link named ifcfg-ethX:X to it and walla, the
server can be the new router (ok, with more changes and the like, but
when you get rid of the old RH7.3 server and put a FC 4 server up, it
easy to just copy the files around)

# ln -s router.ifcfg ifcfg-eth0:1
# ifup eth0:1

router.ifcfg contains:
# if we're named ifcfg-eth? and "sourced" then get my iface name!
if [ -n "$BASH_SOURCE" ]; then
DEVICE="${BASH_SOURCE##*-}"
ONBOOT=yes
fi
BOOTPROTO=static
IPADD=192.168.1.1
<more ifcfg vars here>

=======================================
so: ifup eth0:1 will be sourced correctly!
Yes, it could use error checking and the like, but this is v0.1 alpha
and it works!

Only took me 3 years to answer myself! And I used to say that
I hate USENET because I never get any answers!

LOL


John Bianchi wrote:
> Hi all
>
> I want to know the name a bash sourced filename from within the sourced
> file. echoing $0 from within a sourced file (ie . sourcefile) will report
> the calling filename.
>
> Specifically, I want to change RedHats DEVICE=eth0 setting inside of
> a file already called /etc/sysconfig/network-scripts/ifcfg-eth0 to
> automagically read eth# part from the filename.
>
> DEVICE=`bin/basename $0 | /bin/cut -f2 -d- `
>
> this sets DEVICE to ifup when called as
> ifup eth0
>
> AsFarAsICanTell network-scripts are sourced into ifup so i have to stick
> with this idea (also hate to change the stock scripts)
>
> Thanks
>
>
>

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com