Продолжаю баловаться с пайтоном и столкнулся с задачей запуска пайтона (который в свою очередь запускает шелл).
Есть кусок html страницы, где 3 поля ввода и одна кнопка.
<form method=POST action="/cgi-bin/copy_schema.py"> <P><B>Enter schema, you want to copy from:</B> <P><input type=text name=user_old> <P><B>Enter new schema name:</B> <P><input type=text name=user_new> <P><B>For creation confurmation, please enter your email address:</B> <P><input type=text name=email> <P><input type=submit> </form>
Ожидается, что из полей получается 3 переменных: user_old, user_new и email
Далее данные передаются в скрипт copy_schema.py:
#!/usr/bin/env python import cgi import os user_old = cgi.FieldStorage() user_new = cgi.FieldStorage() email = cgi.FieldSotrage() doc_yes = """ <html> <head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <title>The job is done!</title> </head> <body> Copy command sended succesfully. Please wait for email confirmation from server, when schema is ready. </body> </html> """ doc_no = """ <html> <head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <title>Error!</title> </head> <body> Command has not been sent to database. Did you fill all forms? </body> </html> """ doc_no_email = """ <html> <head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <title>Error!</title> </head> <body> You didn't fill the "email" form. Command has been sended successfully, but you won't receive email about creation comfurmation. </body> </html> """ if 'email' in email: if 'user' in user_old: if 'user' in user_new: user_new = cgi.escape(user_new['user'].value) user_old = cgi.escape(user_old['user'].value) email = cgi.escape(email['email'].value) os.system('copy_schema.sh {0} {1} {2} > dev/null 2>$1'.format(user_old, user_name, email)) print(doc_yes) else: print(doc_no) else: print(doc_no) else: print(doc_no)
Сам скрипт copy_schema.sh выглядит так:
#!/bin/bash -l sqlplus -S SYSTEM/MANAGER <<<"drop user $2 cascade;" sqlplus -S SYSTEM/MANAGER <<<"create user $2 identified by $2;" sqlplus -S SYSTEM/MANAGER <<<"grant connect to $2;" sqlplus -S SYSTEM/MANAGER <<<"create database link tmp_$$ connect to system identified by manager using 'localhost:1521/orcl';" impdp system/manager nologfile=Y remap_schema=$1:$2 network_link=TMP_$$ schemas=$1 EXCLUDE=STATISTICS sqlplus -S SYSTEM/MANAGER <<<"drop database link tmp_$$;" [[ -n "$3" ]] && /usr/sbin/sendmail $3 <<<"Your export import task from $1 to $2 has been completed!"
Есть вопрос по двум фрагментам:
user_old = cgi.FieldStorage() user_new = cgi.FieldStorage() email = cgi.FieldSotrage()
Так правильно получать данные с html странички?
и по этому кусочку:
user_new = cgi.escape(user_new['user'].value) user_old = cgi.escape(user_old['user'].value) email = cgi.escape(email['email'].value) os.system('copy_schema.sh {0} {1} {2} > dev/null 2>$1'.format(user_old, user_name, email))
Правильно ли здесь с точки зрения синтаксиса?
Всем добра!