AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-957309

AmelieAudet's questions

Martin Hope
AmelieAudet
Asked: 2022-03-31 04:49:30 +0800 CST

继续声明不能正常工作 - bash

  • 0

对于上下文,我有一个使用 ssh 的多台机器的基础设施。我们通过 ssh 在没有密码的机器上以 root 身份连接,感谢每台机器上的 authorized_keys 文件。我们定期在我们的基础设施中添加新机器。

有问题的是创建一个脚本:

  1. ping 所有机器(通过解析包含我们所有机器名称的文件)
  2. 如果 ping 成功,请在没有密码的情况下测试 ssh 连接(使用命令ssh -o BatchMode=yes $machine uname -a)
  3. 如果 ssh 不起作用并且是因为此消息:(Are you sure you want to continue connecting (yes/no)?例如,因为它是与这台机器的第一个 ssh 连接),那么使用期望脚本,发送“yes”
  4. 如果 ssh 不起作用并且是因为要求输入密码,那么使用期望脚本,发送“CTRL + C”

我的问题是这两个条件 3. 和 4. 都可能发生在一台机器上,我不知道如何在我的脚本中使用 continue 语句。

这种特定情况适用于要求“是”但之后也要求输入密码的机器。

这是脚本的样子:

for machine in `cat ${liste} | grep -v \#`
do

ping -c1 ${machine} 2>&1 >/dev/null

if [ $? -eq 0 ]
then
    echo ${machine} >> ${pingok}    
    ssh -o BatchMode=yes ${machine} uname -a &> $verifssh 2>&1    
    echo $? > ${exitcode}
    
    if grep -q "255" "$exitcode"
    then        
        cut -c 15-74 $verifssh > $verifssh2
                
        if grep "ication failed." "$verifssh2"        
        then                
            expect ${scriptexpectknownhosts} ${machine} 2>&1 >/dev/null
            
            continue 3 
                        
        elif grep "Permission denied (publickey,password,keyboard-interactive)." "$verifssh2"        
        then        
            expect ${scriptexpectknownhosts} ${machine} 2>&1 >/dev/null            
            echo "${machine}   ->  The machine asks for a password" >> "${sshnok}"           
        fi
                
    elif grep -q "0" "$exitcode"   
    then   
        echo "${machine} works with ssh"
        echo "${machine}" >> ${sshok}               
    fi
    
else
    echo "${machine}" >> "${pingnok}"     
fi

done

这是期望脚本(它处理这两种情况):

set machine [lindex $argv 0]

spawn ssh $machine

expect {
    "Are you sure you want to continue connecting (yes/no)? "  {send "yes\r";exp_continue}
    -exact "Password: " {close}
    -re $prompt {send "exit\r";close}
}

所以简而言之,我的问题是,对于要求“是”答案然后需要密码的机器,我想在${sshnok}文件中注册它们但continue不起作用。我试过continue//它仍然不想回到上一个循环continue 2。continue 3

linux scripting bash ssh expect
  • 1 个回答
  • 87 Views
Martin Hope
AmelieAudet
Asked: 2022-03-04 07:19:59 +0800 CST

尽管配置说端口 587,Postfix 仍然使用端口 25

  • 1

我有一个后缀服务器,它是主邮件服务器的中继。

当我在其上执行 telnet 时,该主邮件服务器将与 587 端口一起使用,它工作得很好:

telnet 10.10.10.10 587
    Trying 10.10.10.10...
    Connected to 10.10.10.10
    Escape character is '^]'.
    220 front1 SMTP Server (Flowmailer SMTP Service) ready

这是我在我的声明中的方式/etc/postfix/main.cf:

relayhost = [10.10.10.10]:587

这就是我在我的声明中的方式/etc/postfix/master.cf:

submission inet n       -       n       -       -       smtpd

之后我重新启动了我的后缀

systemctl restart postfix

并且到目前为止没有收到任何错误消息。

然后我尝试通过我的中继发送电子邮件,这是我遇到的错误:

2022-03-03T11:27:31.031822+01:00 mypostfix postfix/error[32000]: 044D63FBFA: to=<[email protected]>, relay=none, delay=0.01, delays=0.01/0/0/0.01, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to 10.10.10.10[10.10.10.10]:25: Connection timed out)

而且我不明白为什么当我说我想使用端口 587 时它一直尝试使用端口 25。我在这里缺少配置文件吗?

编辑:文件的其余部分main.cf:

compatibility_level = 2
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/lib/postfix/bin/
data_directory = /var/lib/postfix
mail_owner = postfix
myhostname = mypostfix.mylocaldomain.com
mydomain = mylocaldomain.com
myorigin = $mydomain
unknown_local_recipient_reject_code = 550
mynetworks = 192.168.1.0/24 (and all other subnets in my domain)
header_checks = regexp:/etc/postfix/header_checks
smtpd_banner = $myhostname ESMTP
debug_peer_level = 2
debugger_command =
         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
         ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
setgid_group = maildrop
html_directory = /usr/share/doc/packages/postfix-doc/html
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/packages/postfix-doc/samples
readme_directory = /usr/share/doc/packages/postfix-doc/README_FILES
biff = no
content_filter =
delay_warning_time = 1h
disable_dns_lookups = no
disable_mime_output_conversion = no
disable_vrfy_command = yes
inet_interfaces = all
inet_protocols = ipv4
masquerade_classes = envelope_sender, header_sender, header_recipient
masquerade_domains =
masquerade_exceptions = root
mynetworks_style = subnet
relayhost = [10.10.10.10]:587
alias_maps = hash:/etc/aliases
canonical_maps = regexp:/etc/postfix/canonical
relocated_maps = hash:/etc/postfix/relocated
sender_canonical_maps = hash:/etc/postfix/sender_canonical
transport_maps = hash:/etc/postfix/transport
mail_spool_directory = /var/mail
message_strip_characters = \0
defer_transports =
mailbox_command =
mailbox_transport = smtp
mailbox_size_limit = 0
message_size_limit = 0
strict_8bitmime = no
strict_rfc821_envelopes = no
smtpd_delay_reject = yes
smtpd_helo_required = no
smtpd_client_restrictions =
smtpd_helo_restrictions =
smtpd_sender_restrictions = hash:/etc/postfix/access
smtpd_restriction_classes = verify_sender_mycompany,verify_sender_world,verify_sender_all
verify_sender_mycompany = check_client_access hash:/etc/postfix/maps/access_client_mycompany
verify_sender_world = check_client_access hash:/etc/postfix/maps/access_client_world
verify_sender_all = check_client_access hash:/etc/postfix/maps/access_client_all
smtpd_recipient_restrictions = check_recipient_access pcre:/etc/postfix/maps/verify_domains,reject_unauth_destination
smtp_sasl_auth_enable = yes
smtp_sasl_security_options =
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = cyrus
smtpd_sasl_path = smtpd
tls_random_source = dev:/dev/urandom
smtpd_tls_protocols = !SSLv2, !SSLv3, TLSv1.1, TLSv1.2
smtpd_tls_ciphers = high
smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3, TLSv1.1, TLSv1.2
smtpd_tls_mandatory_ciphers = high
smtpd_tls_security_level = none
smtp_tls_mandatory_protocols = !SSLv2, !SSLv3, TLSv1.1, TLSv1.2
smtp_tls_mandatory_ciphers = high
smtp_tls_security_level = may
tls_high_cipherlist = aNULL:-aNULL:HIGH:@STRENGTH
smtp_use_tls = no
smtp_enforce_tls = no
smtp_tls_CAfile =
smtp_tls_CApath =
smtp_tls_cert_file =
smtp_tls_key_file =
smtp_tls_session_cache_database =
smtpd_use_tls = no
smtpd_tls_auth_only = no
smtpd_tls_loglevel = 3
smtpd_tls_CAfile = /etc/ssl/certs/mylocaldomain.com-WC-2022.pem
smtpd_tls_CApath =
smtpd_tls_cert_file = /etc/ssl/certs/mylocaldomain.com-WC-2022.cer
smtpd_tls_key_file = /etc/ssl/private/other-WC-2022.key
smtpd_tls_ask_ccert = yes
smtpd_tls_exclude_ciphers = RC4
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
virtual_alias_maps = hash:/etc/postfix/virtual

我的域也是mylocaldomain.com,我正在尝试向自己发送一封电子邮件,为此[email protected]我使用包含transport此行的文件:

company.com             smtp:10.10.10.10
linux email smtp postfix
  • 1 个回答
  • 591 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve