使用bash自动回答石墨安装的django同步提示

时间:2012-04-15 17:25:56

标签: bash ubuntu chef

我正在使用厨师在ubuntu上自动安装石墨。我需要使用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

由于

5 个答案:

答案 0 :(得分:3)

由于我遇到了同样的问题并使用了预期解决了我想我可以分享我写的期望脚本:

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
     }
}

请记住自定义默认值admin和密码。

答案 1 :(得分:2)

您可以尝试Expect。我从未在sftp以外的任何地方使用它,但它应该适用于任何交互式应用程序。

答案 2 :(得分:1)

如果您需要解决“输入”问题并希望使用结构自动执行管理员创建,请考虑将--noinput标记传递给 syncdb ,然后加载数据包< / strong>已创建用户数据。

看看这里:django fabric syncdb

答案 3 :(得分:0)

只是将数据作为stdin传递给流程工作吗?

printf "%s\n" yes admin test@example.com test101 test101 | sudo python ...

sudo sh -c 'printf "%s\n" yes admin test@example.com test101 test101 | python ...'

答案 4 :(得分:0)

我刚发现了这个,但我想说没有而不是。所以这是一个基于unicoletti示例的最小期望脚本。

set timeout -1                                                                                                                                                          
spawn "./your_django_script.sh"                                                                                                                                     
expect {                                                                                                                                                                
    "Would you like to create one now" {                                                                                                                                
            send "no\r"                                                                                                                                                 
            exp_continue                                                                                                                                                
     }                                                                                                                                                                  
}