Hi ,
i'm in way of doing a small cgi to backup/restore database,
i'm not a programmer so... ill be able to pass the paramater from an html to the cgi but dont know how to place this parameter inside the cgi to do what i want... :
If i want to pass parameter (dbname, dbusername, pass how i can do that ?
# -Cgi that work for get backup of mysql--------------------------
#!/bin/bash
FILE=mysqlbackup.sql
NAME=mydbusername
PASS=mypasss
DB=mydb
echo "Content-type: text/plain"
echo
echo "Tried to export file: "$FILE
/usr/local/psa/mysql/bin/mysqldump --quote-names -u $NAME --password=$PASS $DB > $FILE
# END--------------------------------------------------
I want to pass parameter from html form like mypass, mydb etc.. to the cmd that get the backup (way to put the form parameter to $pass $db etc....
How i can do that ?
Thanks !
Using Cgi-lib.pl ill be able to pass the parameter from a form
to this cgi whitout problem, but i can't place it in the mysql to be working right...
# ---------------------------------------------------------
#!/usr/bin/perl -Tw
require 5.001;
use strict;
require "cgi-lib.pl";
MAIN:
{
my (%input, # The CGI data
$text, # Munged version of the text field entered by the user
$field); # Each of the fields (used for testing)
# Read in all the variables set by the form
&ReadParse(\%input);
# Check that everything has been entered
foreach $field (qw(name color quest swallow text)) {
&CgiDie("Error: Missing field '$field'\n") unless defined $input{$field};
}
# Print the header
print &PrintHeader;
print &HtmlTop ("cgi-lib.pl demo form output");
# Do some processing, and print some output
($text = $input{'text'}) =~ s/\n/\n<BR>/g;
# ----------------------------------------------->>>>>
# my problem start here
#
# my input is like
# $input{'filenamesql'}
# $input{'dbusername'}
# $input{'pass'}
# $input{'dbname'}
# i want to pass this to the mysql cmd beyong...
FILE=$input{'filenamesql'}
NAME=$input{'dbusername'}
PASS=$input{'pass'}
DB=$input{'dbname'}
echo "Content-type: text/plain"
echo
echo "essay de faire le backup dans un fichier: "$FILE
/usr/local/psa/mysql/bin/mysqldump --quote-names -u $NAME --password=$PASS $DB > $FILE
# -then finish here--------------------------->>>>>
print &HtmlBot;
}
# --end of script--------------------------------------------------
thanks for any help
priyadi
06-09-2002, 11:34 AM
I don't quite understand your last script. It seems that you are trying to mix perl script with sh script, it won't work.
You need to use $ sign before any scalar variables including assignment (ie. $FILE=$input{'filenamesql'} instead of FILE=$input{'filenamesql'}). To invoke mysqldump in perl, you need to use 'system'.
yes i will have mixed perl script with sh scrip :-(
Ok so i can use like
$FILE=$input{'filenamesql'}
Those the mysql cmd will be good ?
/usr/local/psa/mysql/bin/mysqldump --quote-names -u $NAME --password=$PASS $DB > $FILE
or if have do do some change to work ?
I'M realy newbi whit plying so mutch whit perl :eek:
thank a lot for your help ..
# tryed this seem not working guess my mysql command not good since they come from Sh script ...
# -----------------------------------------------------------------------
#!/usr/bin/perl -tw
require 5.001;
use strict;
require "cgi-lib.pl";
MAIN:
{
my (%input, # The CGI data
$text, # Munged version of the text field entered by the user
$field); # Each of the fields (used for testing)
# Read in all the variables set by the form
&ReadParse(\%input);
# Check that everything has been entered
foreach $field (qw(name color quest swallow text)) {
&CgiDie("Error: Missing field '$field'\n") unless defined $input{$field};
}
# Print the header
print &PrintHeader;
print &HtmlTop ("cgi-lib.pl demo form output");
# Do some processing, and print some output
($text = $input{'text'}) =~ s/\n/\n<BR>/g;
$FILE=$input{'filenamesql'}
$NAME=$input{'dbusername'}
$PASS=$input{'pass'}
$DB=$input{'dbname'}
echo "Content-type: text/plain"
echo
echo "try to do backup in file: "$FILE
/usr/local/psa/mysql/bin/mysqldump --quote-names -u $NAME --password=$PASS $DB > $FILE
print &HtmlBot;
}
# -----------------------------------------------------------------------
thanks for any help !
:bawling:
priyadi
06-09-2002, 11:07 PM
If you are more familiar with sh scripts, then I suggest to stick with sh scripts. The only thing missing from your script is getting parameters. bashlib (http://bashlib.sourceforge.net/) seems to able to do that. There are several others if you search freshmeat.net.