1

I have build a form (using JavaScript, jQuery, PHP and HTML) that makes it easy for the non-technical people to compose and fire the command that creates an ISO image containing the CentOS Linux and a company application built along with it. Here is the actual command with sample variables.

./test.pl --verbose --output tvmTEST.iso --virtual --isv 4.1.5.1.4147.8.0  --64bit --netproto static --hostname tvmTEST --address 192.168.5.235 --netmask 255.255.255.0 --gateway 192.168.5.252 --nameserver 192.168.5.21,192.168.5.2

This exact command works properly when fired from the shell while logged in as root and the ISO gets created successfully. However, it doesn't work through the GUI. The form composes the command properly and passes it to the PHP code where I am calling the perl program. I had the command composed by PHP program tested in the shell and it created the ISO! Here is the perl program that builds the ISO image. It is being run as user apache when fired through the form. But, it dies at line # 665 where it says:

system("sudo mount -o loop $c{centosiso} $mp") and die;

I tried printing the string passed to system() above and it printed:

sudo mount -o loop /tmp/test.pl-cache/CentOS-5.4-x86_64-bin-1of7.iso /mnt/CentOS

So, I tried firing this command through the shell and it actually mounted the ISO! However, the permissions for /mnt/CentOS changed to 755. Its not clear to me WHY? Note that I tested it with and without sudo in that line above.

And, prior to this, the permissions for /mnt/CentOS were set to 777 and owner was set as apache! Is these permissions the reason why my form isn't working? Am I on the right track?

Rahul Desai
  • 15,242
  • 19
  • 83
  • 138
  • sudo may not work for apache, – CyberDem0n Aug 16 '12 at 18:43
  • I had tried it without sudo, it dint make any difference. – Rahul Desai Aug 16 '12 at 18:46
  • 1
    You are ignoring the error message. Either add [`use autodie qw(:all);`](http://stackoverflow.com/a/3478060) to your program and remove `and die`, or change the it to `die "mount failed: $!";`. – daxim Aug 16 '12 at 18:48
  • @daxim looks like I need to install `IPC::System::Simple`, it did not work just by adding `use IPC::System::Simple;` `use autodie qw(:all);` at the beginning of the code. Am I putting it in the wrong place? how do I install that module (sorry I am new to it)? – Rahul Desai Aug 16 '12 at 19:07
  • No, at the beginning is fine. /// From the [Stack Overflow Perl FAQ](http://stackoverflow.com/questions/tagged/perl?sort=faq): [What's the easiest way to install a missing Perl module?](http://stackoverflow.com/questions/65865/whats-the-easiest-way-to-install-a-missing-perl-module) – daxim Aug 16 '12 at 19:09
  • Thanks, I will do that. Another alternative could be to pass the password as we are doing sudo. Do you know how we can pass it in the same line where the mount command is? or maybe after that. – Rahul Desai Aug 16 '12 at 19:18

1 Answers1

1

You might also try using qx( … ) around the command instead of using the system function.

This operator tells Perl to run the command in a shell. I have had it happen that system would fail where the same command would run with qx.

I preferred that solution to trying to find out why system command was being obstinate.

One nice difference is that while system will return the exit value of the command, and qx returns the output of the command, so you can assign the result to a variable and print that for debugging purposes.

daxim
  • 39,270
  • 4
  • 65
  • 132
truks
  • 11
  • 2