我正在尝试编写代码来自动执行/etc/init.d/oracleasm configure命令,因为它需要4个输入才能继续进行。
Default user to own the driver interface [grid]: grid
Default group to own the driver interface [y]: oinstall
Start Oracle ASM library driver on boot (y/n) [y]: y
Scan for Oracle ASM disks on boot (y/n) [y]: y
通常,什么是编写代码以实现此目标的最佳方法。请给我建议。
如果您有一个可以非交互式运行的命令,但可以使用来运行交互式命令会更好expect
。根据您的示例,它将为:
bash 'OracleASM' do
user 'root'
code <<-EOF
/usr/bin/expect -c 'spawn /etc/init.d/oracleasm configure
expect "Default user to own the driver interface [grid]: "
send "grid\r"
expect "Default group to own the driver interface [y]: "
send "oinstall\r"
expect "Start Oracle ASM library driver on boot (y/n) [y]: "
send "y\r"
expect "Scan for Oracle ASM disks on boot (y/n) [y]: "
send "y\r"
expect eof'
EOF
end
重要的/etc/init.d/oracleasm configure
是要成为幂等命令,这意味着您可以运行一次,两次或一百次,并且其行为和结果系统将相同。如果不是这种情况,则您需要对命令(only_if
或not_if
)进行一些防护,以在需要时仅运行该命令:
bash 'OracleASM' do
user 'root'
code <<-EOF
....
EOF
not_if { ::File.exists?('/...') }
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句