确定尝试将SQL查询写入文本文件。我试过猫,但没有运气。
以下是我想写的文件:
USE vsftpd;
CREATE TABLE `accounts` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`username` VARCHAR( 30 ) NOT NULL ,
`pass` VARCHAR( 50 ) NOT NULL ,
UNIQUE (
`username`
)
) ENGINE = MYISAM ;
quit;
这是我使用cat或echo时得到的(也许我需要某种切换?):
USE vsftpd;
CREATE TABLE (
uid=0(root) gid=0(root) groups=0(root) INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
VARCHAR( 30 ) NOT NULL ,
VARCHAR( 50 ) NOT NULL ,
UNIQUE (
)
) ENGINE = MYISAM ;
quit;
答案 0 :(得分:2)
如果没有看到您正在使用的确切命令,很难说如何修复此问题,但我怀疑shell正在对您的文本执行backquote substitution。所以你在哪里
CREATE TABLE `accounts`
bash尝试执行accounts
作为命令,并将反引号文本替换为命令的标准输出。由于你的路径中可能没有这样的命令,反引号部分会在输出中消失。
尝试使用反斜杠转义每个`字符,如下所示:
CREATE TABLE \`accounts\`
答案 1 :(得分:1)
如果在shell中使用反引号运行,它将评估``中包含的命令。因此,一种方法是使用单引号:
$ echo ' USE vsftpd;
CREATE TABLE `accounts` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`username` VARCHAR( 30 ) NOT NULL ,
`pass` VARCHAR( 50 ) NOT NULL ,
UNIQUE (
`username`
)
) ENGINE = MYISAM ;
quit;
' > file.sql
$ more file.sql # verify content is correct
答案 2 :(得分:0)
无论如何我猜我现在可以发布整个事情以防其他人在那里使用vsftpd而你帮了我。下面是用于vsftpd的脚本和mysql用于虚拟用户。除了创建新用户之外,这里有一些你可以弄清楚如何从给出的内容写出来的东西:
#!/bin/bash
while [[ "$yn" != "Yes" && "$yn" != "Y" && "$yn" != "y" && "$yn" != "yes" ]]; do
echo "name for your root password for MySQL"
read rpsql
echo "name for your primary FTP user"
read puftp
echo "what's you ftp password?"
read pftp
echo "what's the IPaddress of this server?"
read fip
echo "What is the Hostname of this server?"
read fhost
echo "You have entered $rpsql as your MySQL password"
echo "You have entered $puftp as your FTP user"
echo "You have entered $pftp as your Primary FTP password"
echo "You have entered $fip as your IP address"
echo "You have entered $fhost as your hostname"
echo "Are all of these correct? (Yes or No)"
read yn
done
echo '######################################################################'
echo '##### Installing, configuring, and creating FTP Users and Shares #####'
echo '######################################################################'
apt-get install vsftpd libpam-mysql mysql-client phpmyadmin
mysqladmin -h nexwrxdemo.com -u root password $rpsql
echo 'CREATE DATABASE vsftpd;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON vsftpd.* TO '$puftp'@'localhost' IDENTIFIED BY '$pftp';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON vsftpd.* TO '$puftp'@'localhost.localdomain' IDENTIFIED BY '$pftp';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON vsftpd.* TO '$puftp'@'$fip' IDENTIFIED BY '$pftp';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON vsftpd.* TO '$puftp'@'$fhost' IDENTIFIED BY '$pftp';
FLUSH PRIVILEGES;
USE vsftpd;
CREATE TABLE `accounts` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`username` VARCHAR( 30 ) NOT NULL ,
`pass` VARCHAR( 50 ) NOT NULL ,
UNIQUE (
`username`
)
) ENGINE = MYISAM ;
quit; ' > vsftpd.db
echo "granting permissions to 'vsftpd' on database 'vsftpd'"
mysql -u root -p$rpsql < vsftpd.db
echo "creating a non-privileged user called 'vsftp' (with the homedir /home/vsftpd) belonging to the group 'nogroup'"
useradd --home /home/$puftp --gid nogroup -m --shell /bin/false $puftp
echo "configuring vsftpd"
echo "backing up vsftpd config file"
cp -r -f -p /etc/vsftpd.conf /backups/
cat /dev/null > /etc/vsftpd.conf
echo 'listen=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
nopriv_user=vsftpd
chroot_local_user=YES
secure_chroot_dir=/var/run/vsftpd
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/certs/vsftpd.pem
guest_enable=YES
guest_username=vsftpd
local_root=/home/vsftpd/$USER
user_sub_token=$USER
virtual_use_local_privs=YES
user_config_dir=/etc/vsftpd_user_conf
' > /etc/vsftpd.conf
mkdir /etc/vsftpd_user_conf
echo "backing up pam/vsftpd config file"
cp -r -f -p /etc/pam.d/vsftpd /orig-config/
cat /dev/null > /etc/pam.d/vsftpd
echo "auth required pam_mysql.so user=$puftp passwd=$psql host=localhost db=vsftpd table=accounts usercolumn=username passwdcolumn=pass crypt=2
account required pam_mysql.so user=$puftp passwd=$psql host=localhost db=vsftpd table=accounts usercolumn=username passwdcolumn=pass crypt=2" > /etc/pam.d/vsftpd
/etc/init.d/vsftpd restart
#may be service vsftpd restart
echo "setting up ftp admin & standard users for websites"
echo "adding new users to ftp database"