Dear Monks. I developped a simple script in Perl that let's me verify if USB key is mounted or not and eventually unmount it.
I am not sure if problem is related to programming or configuration...
Basic issue is: When I execute those scripts in terminal using `Perl` it works perfectly fine, althou when I do it in the browser using `mod_perl` it shows some pretty odd behaviour.
This program simply outputs a message that indicates if the system device `/dev/sda1` is mounted in the system.
#!/usr/bin/perl use strict; use warnings; print "Content-type:text/html\n\n"; print "<html><head><title>USB test</title>"; print "</head><body>"; my $mounted = `df -h | grep /dev/sda1`; if ($mounted eq '') { print '<h1>USB device not connected</h1>'; print $mounted; } else { print '<h1>Device is connected</h1>'; } print '</body></html>';
This program umounts the `/dev/sda1` device from the system.
#!/usr/bin/perl print "Content-type:text/html\n\n"; print "<html><head><title>Umount</title></head><body>"; system("sudo", "umount", "/dev/sda1"); print "</body></html>";
1. Manually mounting the device `/dev/sda1`, (it is declared in `fstab`):
$ mount -a
Making sure the device is mounted in the system:
$ mount /dev/sda1 on /mnt/usbstick type vfat (rw,relatime,uid=1000,gid=100 +0,fmask=0137,dmask=0027,codepage=437,iocharset=ascii,shortname=mixed, +utf8,errors=remount-ro)
2. Executing `panelmin.pl` in the web browser (I will use curl for the purpose of clean output):
$ curl http://localhost/cgi-bin/admin/Q/panel/panelmin.pl <html><head><title>USB test</title></head><body><h1>Device is conn +ected</h1></body></html>
As we can see, the output is correct. It detected the through linux command `df -h` that the device `/dev/sda1` is mounted in the system.
2. Executing `umount.pl` in the web browser in order to umount the device:
$ curl http://localhost/cgi-bin/admin/Q/panel/umount.pl <html><head><title>Umount</title></head><body></body></html>
3. Verifying if the device is umounted using both `panelmin.pl` script in the web browser and linux command line.
$ curl http://localhost/cgi-bin/admin/Q/panel/panelmin.pl <html><head><title>USB test</title></head><body><h1>USB device not + connected</h1></body></html>
Seems to be correct, but let's verify it manually with `df -h` command:
$ df -h | grep /dev/sda1 /dev/sda1 15G 366M 15G 3% /mnt/usbstick
As we can see the device is still mounted in the system.
4. Let's retry the whole process but this time instead of executing scripts in the browser we will launch them manually with `Perl` in the terminal. First lets umount the device. This will also show that the user is in sudoers and script can umount it.
$ sudo umount /dev/sda1 $ df -h | grep /dev/sda1
Let's repeat the process.
$ mount -a (as superuser) $ df -h | grep /dev/sda1 /dev/sda1 15G 366M 15G 3% /mnt/usbstick
And finally the test:
$ perl panelmin.pl Content-type:text/html <html><head><title>USB test</title></head><body><h1>Device is conn +ected</h1></body>
$ perl umount.pl Content-type:text/html <html><head><title>Umount</title></head><body></body></html>
$ perl panelmin.pl Content-type:text/html <html><head><title>USB test</title></head><body><h1>USB device not + connected</h1></body></html>
Now `df -h | grep /dev/sda1` returned empty string, it has proven that `umount.pl` managed to umount the device from the system, but only if executed in the shell with `Perl`.$ df -h | grep /dev/sda1
use autodie qw(:all)
The fact it works with `Perl` and not with `mod_perl` is not that surprising, what I find the most strange is with `mod_perl` the script `panelmin.pl` seems to works fine with it's `system()` launch and suddenly after executing `umount.pl` it does not work correctly anymore. For now I am out of ideas, I find this behaviour odd and I count on you guys. I hope someone knows what should I do. Thanks.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |