0

I have some code in my postwwwacct script which doesn't work, it doesn't import the sql file

shell_exec("cd /home/".$opts['user']."/public_html/sbans/sql/");
$command="mysql -u ".$opts['user']." -p".$opts['pass']." ".$opts['user']."_bans < data.sql";
shell_exec($command);

However after account creation i can manually run in ssh

cd /home/jason/public_html/sbans/sql/
mysql -u jason -pmypass jason_bans < data.sql

Which then works.

What is the problem with the php code in postwwwacct?

Sorry for re-editing your edit but the file does not have php extension i manually call the php compiler by using

#!/usr/local/bin/php -q
5
  • What error do you get? Do you have permissions to run shell commands? Commented Aug 22, 2012 at 11:52
  • echo $command; to see if it's valid command Commented Aug 22, 2012 at 11:53
  • i cant see the output since this runs via cpanel on account creation Commented Aug 22, 2012 at 12:01
  • Other shell commands are working , such as too copy files so it shouldn't be a permissions issue Commented Aug 22, 2012 at 12:02
  • Nerd sorry but it shouldnt have a space while manually running the shell command i need to type -pmypass no space , for it to work Commented Aug 22, 2012 at 12:03

2 Answers 2

1

Off the top of my head, are you sure the file data.sql is in all the different user's sql folders? You could also create a seperate bash script and call it in your script, that worked for me before, you just pass in the parameters with something like this:

$t = shell_exec("path/command.sh '$opts['user']' '$opts['pass']' 2>&1");
echo $t

and in the bash script start off like this to get the variables: #!/bin/bash

 #Get variables needed

 user=$1
 pass=$2

You can then proceed to use the variables as any normal bash variables, and if it is still not working for you becouse of the 2>&1 at the end of your shell_exec command you'll be able to debug it alot easier.

Good luck!

Sign up to request clarification or add additional context in comments.

2 Comments

I am copying the sql file to each users dir using a previous shell command, so its definitely there. Id like to stick with php since the rest of the code is.
I'd still highly recommend you add the 2>&1 after your shell_exec command anyway, it prints out errors and if you echo $command you will have more information as of why it's failing
0

the problem is that shell_exec does cd and finishes so the command which would do the import with the sql is not found and failed.

try something like this :

<?php
$command="mysql -u ".$opts['user']." -p".$opts['pass']." ".$opts['user']."_bans < data.sql";
$output = shell_exec("cd /home/".$opts['user']."/public_html/sbans/sql/ && ".$command);

and if you want to see the result of your command just do

echo $output

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.