使用bash自动回答django sync提示石墨的安装
问题描述:
我正在使用厨师在ubuntu上自动安装石墨。我需要使用bash或任何其他方式自动化python manage.py syncdb。使用bash自动回答django sync提示石墨的安装
[email protected]:/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: [email protected]
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: [email protected]
Password: test101
Password (again): test101
感谢
答
只需将数据作为标准输入输出到过程工作?
printf "%s\n" yes admin [email protected] test101 test101 | sudo python ...
或
sudo sh -c 'printf "%s\n" yes admin [email protected] test101 test101 | python ...'
答
因为我有同样的问题,用解决它期待我想我可以分享我写的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 "[email protected]\r"
expect "Password"
send "admin\r"
expect "Password"
send "admin\r"
exp_continue
} "Migrated" {
expect eof
}
}
记住自定义默认管理员和密码。
答
我刚刚发现这个,但我想说没有而不是是的。所以这里是基于unicoletti示例的最小期望脚本。
set timeout -1
spawn "./your_django_script.sh"
expect {
"Would you like to create one now" {
send "no\r"
exp_continue
}
}
谢谢...更好的是,他们有一个python的优点:) – Tampa 2012-04-15 20:55:02