bash - 使用 bash 自动回答 Graphite 安装的 django sync 提示

标签 bash ubuntu chef-infra

我正在使用 Chef 在 Ubuntu 上自动安装 Graphite。我需要使用 bash 或任何其他方式自动化 python manage.py syncdb。

ubuntu@ip-xxx-xxx-xxx:/opt/graphite/webapp/graphite$ sudo python manage.py syncdb
Creating tables ...
Creating table account_profile
Creating table account_variable
Creating table account_view
Creating table account_window
Creating table account_mygraph
Creating table dashboard_dashboard_owners
Creating table dashboard_dashboard
Creating table events_event
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table auth_message
Creating table django_session
Creating table django_admin_log
Creating table django_content_type
Creating table tagging_tag
Creating table tagging_taggeditem

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (Leave blank to use 'root'): admin
E-mail address: test@gmail.com
Password: 
Password (again): 
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
No fixtures found.

我需要使用以下命令自动执行以下提示

Would you like to create one now? (yes/no): yes
Username (Leave blank to use 'root'): admin
E-mail address: test@gmail.com
Password: test101
Password (again): test101

谢谢

最佳答案

由于我遇到了同样的问题并使用 expect 解决了它,我想我可以分享我编写的 expect 脚本:

set timeout -1
set program [ lindex $argv 0 ]
eval spawn $program [ lrange $argv 1 end ]
expect {
    "Would you like to create one now" {
            send "yes\r"
            expect "Username"
            send "admin\r"
            expect "E-mail"
            send "test@gmail.com\r"
            expect "Password"
            send "admin\r"
            expect "Password"
            send "admin\r"
            exp_continue
     } "Migrated" {
            expect eof
     }
}

请记住自定义默认管理员和密码。

关于bash - 使用 bash 自动回答 Graphite 安装的 django sync 提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10164323/

相关文章:

linux - 如何用日期解析时区

python - 获取当前 screen session 的名称

docker - GitHub Action Ansible 检查 ubuntu :focal hangs on setting up tzdata without dialog

ubuntu - Sidekiq 服务未启动

chef-infra - CHEF,如何替换 Chef Solo 中的 node.set/node.save ?

chef-infra - 运行 Chef 客户端抛出 404 "Object Not Found"(Net::HTTPServerException)

mysql - centos 7 Chef mysql 自定义目录

bash,文本文件在最后一个空格之前删除每行中的所有文本

ubuntu - 手动添加ssl证书到可信

linux - bash 脚本中的 source/etc/profile