in reply to mount cifs using perl and sudo and mount

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'.


--
"Language shapes the way we think, and determines what we can think about."
-- B. L. Whorf

Replies are listed 'Best First'.
Re^2: mount cifs using perl and sudo and mount
by Anonymous Monk on Aug 30, 2010 at 00:22 UTC
    hi! thanks for the reply, but the problem if I didnt use the gnome-terminal is that i could never run my program inside a launcher. i could use the "run in terminal" mode. but i cannot use that because the program that i am using it (a very big program) cannot be run using "run in terminal" mode. so for my mount to work, i should be able to launch it without the terminal. your codes works fine if typed in a terminal. but it doesnt mount if there are no terminal. i thinks the sudo has something to do with it. but im not really sure.