Perl脚本获取.bash_profile中变量
最近在修改MySQL mha自动切换脚本,发现脚本里面的ip和路径等变量都写死了,不利于MHA相关脚本移植使用,通过自定义mha环境变量和VIP相关变量来移植.
设置MHA相关环境变量
export MHA_HOME=/home/mysql/mha
export VIP=192.168.68.135/24
export VIP_ONLY=192.168.68.135
. ~/.bash_profile
测试:
vi 3.pl
#!/usr/bin/env perl
my $mha_home = $ENV{MHA_HOME};
my $vip = $ENV{VIP};
my $vip_only = $ENV{VIP_ONLY};
print "### Geting env from .bash_profile ###\n";
print "mha_home: $mha_home\nvip: $vip\n$vip_only: $vip_only\n";
[mysql@lissen-mha-manager ~]$ perl 3.pl
### Geting env from .bash_profile ###
mha_home: /home/mysql/mha
vip: 192.168.68.135/24
192.168.68.135: 192.168.68.135