Click to See Complete Forum and Search --> : Can someone look at my script


hazmtrl
10-20-2003, 04:10 PM
Something is not working correctly, this is the part I have, and working on...

if ($error == "0") {
$a = substr($login,0,1);
$aa = substr($login,0,2);
$dir = "/home/members/" . $a . "/" . $aa . "/" . $login . "";
exec("mkdir /home/members/$a");
exec("mkdir /home/members/$a/$aa");
exec("mkdir /home/members/$a/$aa/$login");
exec("mkdir /home/members/$a/$aa/$login");
exec("chown apache:users /home/members/$a");
exec("chown apache:users /home/members/$a/$aa");
exec("/usr/sbin/useradd -d $dir -s /sbin/nologin -g users $login");
exec("/usr/sbin/usermod -d $dir -s /sbin/nologin -g users $login");
exec("chown -R $login:users /home/members/$a/$aa/$login");
exec("chmod -R 755 /home/members/$a/$aa/$login");
exec("echo pass1 | passwd --stdin $login");

Everything seems to work through mkdir. I have created the directories, but they are not chowned no useradd in the /etc/passwd or shadow file. Can someone tell me what I am doing wrong?

Also since I'm asking, when adding a user to the unix system, how can I use the unix username and passwds for login? I have looked through scripts but everything turns me to MySQL. I do not want to use it for this since I am using a webbased mail system.

Thanks

micio
10-21-2003, 09:54 AM
I don't think exec is the right way to do it because it transfers the execution to another script/command. Think about .xinitrc, you use exec window_manager so that when the window_manager ends X ends too, so, it may be guessed that after the first mkdir exits the whole scripts aborts ...

You can simply invoke the command from the shell script:

mkdir /home/members/$a

To debug a shell script use

$/bin/sh option script

were option can be:
-n Reads all commands, but does not execute them.
-v Displays all lines as they are read.
-x -Displays all commands and their arguments as they execute. (shell tracer)

micio

hazmtrl
10-21-2003, 10:09 AM
Thank you very much!!!

I will give it a try