You can't get the status of the command by using backticks; that's not what they're for (they're used if you want to capture the output of the command.) If you want the status, you need to use the 'system' function. Here, I'm going to loop-mount an ISO file on a directory in /tmp, then unmount it - with error checking:
#!/usr/bin/perl -w use strict; system "sudo mount $ARGV[0] /tmp/mnt -o loop=/dev/loop0" and die "mount: ", $? >> 8, "\n"; print "Mounted successfully.\n"; system "sudo umount /tmp/mnt -l" and die "umount: ", $? >> 8, "\n"; print "Unmounted successfully.\n";
And here's the output:
ben@Jotunheim:/tmp$ ./mt ubuntu_9_10.iso Mounted successfully. Unmounted successfully. ben@Jotunheim:/tmp$ ./mt fake_filename fake_filename: No such file or directory mount: 32
The return code from 'mount', 32, is listed in the man page as 'mount failure'.
In reply to Re: mount cifs using perl and sudo and mount
by oko1
in thread mount cifs using perl and sudo and mount
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |