We help IT Professionals succeed at work.

why expect can't found if run from apache server

i have problem with my expect

1. if we run script close_all.sh from terminal openBSD it's run normal
2. if we run test.php to run close_all.sh from php CLI it's normat too

but if we run from browser with Apache server the script error like this

./close_all.sh[37]: expect: not found

apache have group wheel

this error appear after we use Eclipse RSE to this server and until now still error

thanks before, please help
#!/bin/bash
expect << EOF
spawn su
expect "*:"
send "$1\n"
expect "*#"
send "chmod  640 /etc/passwd \n"
expect "*#"
send "chmod  600 /etc/master.passwd \n"
expect "*#"
send "chmod  640 /etc/pf.conf \n"
expect "*#"
send "chmod  640 /etc/hosts \n"
expect "*#"
send "chmod  640 /etc/hostname.* \n"
expect "*#"
send "chmod  640 /etc/mygate \n"
expect "*#"
send "chmod  644 /etc/resolv.conf \n"
expect "*#"
send "chmod  640 /etc/ssh/sshd_config \n"
expect "*#"
send "chmod  644 /etc/dhcpd.conf \n"
expect "*#"
send "chmod  644 /etc/myname \n"
expect "*#"
send "chmod  644 /etc/group \n"
expect "*#"
send "exit\n"
exit

EOF

Open in new window

<?php
$command ="sh /close_all.sh passadmin";
$closefile =shell_exec($command);
echo $closefile;
?>

Open in new window

Comment
Watch Question

Commented:
That's because your terminal window has a login session with environment variables like $PATH.

You expect might be located in /usr/local/bin/expect and as long as path contains /usr/local/bin, you can call expect without any path.
If, however, your web server calls the script, it does not have a login session, no environment, no $PATH. It simply won't find expect.

In order to find it, you have to append the whole path to the first expect line:

/usr/local/bin/expect << EOF

You can find YOUR path for expect by typing:

which expect

in you shell session.
Yudo Hartono Tri SunuPHP Programmer

Author

Commented:
this works perfect for me