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