问:Bash脚本从多个文件中的变量运行多个命令

时间:2018-07-31 14:54:29

标签: bash shell scripting

在循环到达每个文件的末尾之前,我遇到了一些问题。

如果我运行代码,并且在每个文件中只有1行,则工作正常。 但是,如果我在文件中包含多于1行,则无法正常工作

我相信我错误地使用了FOR循环,将不胜感激任何帮助。

#!/bin/bash
domain="$(cat domains.txt)"
ip="$(cat ips.txt)"
pub_dkim_key="$(cat pub_dkim_key.txt)"
password="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-25};echo;)"

# -- ~~ --  -- ~~ --  -- ~~ --  -- ~~ --  -- ~~ --  -- ~~ --  -- ~~ --  -- ~~ -- #
for domain in $domain
do
# Add domains
v-add-domain admin $domain $ip restart

# Delete DNS Records
v-delete-dns-record admin $domain 16
v-delete-dns-record admin $domain 15

# Add NS A Records
v-add-dns-record admin $domain NS1 A $ip
v-add-dns-record admin $domain NS2 A $ip

# Change localhost to correct domain
v-change-dns-record admin $domain 1 ns1.$domain.
v-change-dns-record admin $domain 2 ns2.$domain.

# Add key1 DKIM
v-add-dns-record admin $domain key1._domainkey TXT "v=DKIM1; k=rsa; p=$pub_dkim_key"

# Add SPF
v-add-dns-record admin $domain @ TXT "v=spf1 mx a ip4:1.1.1.1/24 include:amazonses.com ~all" 

# Add DMARC
v-add-dns-record  admin $domain _dmarc TXT "v=DMARC1; p=none; sp=none; rua=mailto:admin@$domain; ruf=mailto:admin@$domain; rf=afrf; pct=100; ri=86400"

# Add email accounts
v-add-mail-account admin $domain admin $password 1024
v-add-mail-account admin $domain abuse $password 1024
v-add-mail-account admin $domain contact $password 1024
v-add-mail-account admin $domain fbl $password 1024
v-add-mail-account admin $domain hostmaster $password 1024
v-add-mail-account admin $domain noreply $password 1024
v-add-mail-account admin $domain postmaster $password 1024
v-add-mail-account admin $domain reply $password 1024

# Add Email Forward
v-add-mail-account-forward admin $domain admin  all@asdfasdf.com
v-add-mail-account-forward admin $domain abuse  all@asdfasdf.com
v-add-mail-account-forward admin $domain contact  all@asdfasdf.com
v-add-mail-account-forward admin $domain fbl  all@asdfasdf.com
v-add-mail-account-forward admin $domain hostmaster  all@asdfasdf.com
v-add-mail-account-forward admin $domain noreply  all@asdfasdf.com
v-add-mail-account-forward admin $domain postmaster  all@asdfasdf.com
v-add-mail-account-forward admin $domain reply  all@asdfasdf.com

# Add Lets-Encrypt SSL
v-add-letsencrypt-domain admin $domain
done
# -- ~~ --  -- ~~ --  -- ~~ --  -- ~~ --  -- ~~ --  -- ~~ --  -- ~~ --  -- ~~ -- #

编辑:

希望这可以使我更清楚地了解所要达到的目标,

我非常希望它使用指定文件中的域/ ip遍历命令,直到到达文件末尾为止

domains.txt 
    a.com 
    b.com 
    c.com 

ips.txt 
    1.1.1.1 
    2.2.2.2 
    3.3.3.3 

pub_dkim_key.txt 
    MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC 
    MIIEowIBAAKCAQEAgr6rzGUQBoi2IICq+RSCDACf 
    bCb3lZAhn0pmaTnMdWaUZmSDvBdfi8UlEs9LeoUn 


First Run   v-add-domain admin a.com 1.1.1.1 restart 
Second Run  v-add-domain admin b.com 2.2.2.2 restart 
Third Run   v-add-domain admin c.com 3.3.3.3 restart 

First Run   v-change-dns-record admin a.com 1 ns1.a.com. 
First Run   v-change-dns-record admin a.com 2 ns2.a.com. 

Second Run  v-change-dns-record admin a.com 1 ns1.a.com. 
Second Run  v-change-dns-record admin a.com 2 ns2.a.com. 

Third Run   v-change-dns-record admin a.com 1 ns1.a.com. 
Third Run   v-change-dns-record admin a.com 2 ns2.a.com. 

etc

0 个答案:

没有答案