LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Mount expression not working in nautilus script (http://www.linuxquestions.org/questions/programming-9/mount-expression-not-working-in-nautilus-script-881802/)

thund3rstruck 05-20-2011 09:01 AM

Mount expression not working in nautilus script
 
I'm sure this is something really stupid but I'm really tired and I'm kind of burned out on ideas, at this point.

Here is a segment from a script (the script is complicated so I'll just post the problem)

Code:

echo "sudo mount -o loop $eFile $eMount" > syntax.txt
sudo mount -o loop $eFile $eMount &> error.log

For debugging, I have the first line that echoes back the command being run (so I can find obvious syntax errors) and the second line runs the command.

The first line returns:
Code:

sudo mount -o loop /home/abigail.dunning/Training/1994-2010\ Linux\ Journal\ Master\ Collection.iso /media/iso/1994-2010\ Linux\ Journal\ Master\ Collection
If this line is cut and pasted into a bash shell it runs and the mount occurs fine.

However, this is being run in a nautilus script and the output of the same mount command is the syntax for mount???

Code:

# contents of error.log
Usage: mount -V                : print version
      mount -h                : print this help
      mount                    : list mounted filesystems
      mount -l                : idem, including volume labels
So far the informational part. Next the mounting.
The command is `mount [-t fstype] something somewhere'.
Details found in /etc/fstab may be omitted.
....

I have really no idea why a command run by bash would work and the same command run by nautilus would fail?

druuna 05-20-2011 09:11 AM

Hi,

Only thing I see is a missing fstype option. Maybe when you do this from a bash shell it is guessed correctly and not so when done from a nautilus script (which I'm not familiar with).

Try changing it to:
Code:

echo "sudo mount -t iso9660 -o loop $eFile $eMount" > syntax.txt
sudo mount -t iso9660 -o loop $eFile $eMount &> error.log

Hope this helps.

thund3rstruck 05-20-2011 09:21 AM

Quote:

Originally Posted by druuna (Post 4361881)
Hi,

Only thing I see is a missing fstype option. Maybe when you do this from a bash shell it is guessed correctly and not so when done from a nautilus script (which I'm not familiar with).

Try changing it to:
Code:

echo "sudo mount -t iso9660 -o loop $eFile $eMount" > syntax.txt
sudo mount -t iso9660 -o loop $eFile $eMount &> error.log

Hope this helps.

Yea, I originally started out defining the iso9660 type and when mount spit back the syntax I figured I'd widdle the mount command down to the fewest possible options to reduce the debugging surface area. There's something deeper going on here because all the variations of the command work when typed into the shell directly but when run in nautilus mount just spits out syntax and ignores the parameters.

Thanks!

Spatior 05-20-2011 06:46 PM

In my expirence the scripts does not handle very well spaces in file names

Code:

sudo mount -o loop /home/abigail.dunning/Training/1994-2010\ Linux\ Journal\ Master\ Collection.iso /media/iso/1994-2010\ Linux\ Journal\ Master\ Collection
Is it possible for you to change the iso filename and to mount it to another directory?

thund3rstruck 05-20-2011 09:12 PM

Quote:

Originally Posted by Spatior (Post 4362331)
Is it possible for you to change the iso filename and to mount it to another directory?

Thanks for the suggestion. Actually the mount point is derived from the $(basename) of the ISO so changing the name would also change the mount point.

Right now I'm trying to troubleshoot with a file on the local system but no, all the ISOs are all on a network share and the environment is a shared small business Windows server. The users can't comprehend the concept that spaces could be a problem (and I'm trying to demonstrate that Linux can be a realistic option for this organization).

I've escaped all the spaces with sed and when the command is run in the shell directly, all is well so there must be something unique to Nautilus causing this problem.

Looks like I'm gonna have to come up with something in python or C if I can't resolve soon.

dwhitney67 05-20-2011 10:55 PM

Quote:

Originally Posted by thund3rstruck (Post 4362398)
I've escaped all the spaces with sed and when the command is run in the shell directly, all is well so there must be something unique to Nautilus causing this problem.

Can you please post how you escaped the white-space?

The following works for a single ISO file that does not have white-space in the filename:
Code:

#!/bin/bash

filepath=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS

file=`basename $filepath`

dir=`echo $file | awk -F "." '{print $1}'`

gksudo -D mountISO "mkdir -p /media/$dir"
gksudo -D mountISO "mount -t iso9660 -o loop $filepath /media/$dir"

And to clean up:
Code:

#!/bin/bash

filepath=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS

file=`basename $filepath`

dir=`echo $file | awk -F "." '{print $1}'`

gksudo -D umountISO "umount /media/$dir"
gksudo -D umountISO "rmdir /media/$dir"

I placed these scripts in ~/.gnome2/nautilus-scripts.

P.S. Obviously the scripts are missing code for error checking.

thund3rstruck 05-21-2011 07:53 PM

Quote:

Originally Posted by dwhitney67 (Post 4362463)
Can you please post how you escaped the white-space?

I do appreciate the response but this is unrelated to the actual problem I'm trying to solve. As mentioned in the original post, this command:

Code:

sudo mount -o loop /home/abigail.dunning/Training/1994-2010\ Linux\ Journal\ Master\ Collection.iso /media/iso/1994-2010\ Linux\ Journal\ Master\ Collection
When run in the bash shell directly works but when its run via a nautilus script it doesn't. The reason I'm absolutely sure that this is the command being run is because I added a debugging line just above this call to record the command being run (just to be absolutely certain; since clearly mount wouldn't be spitting out syntax unless there was a syntactical error.)

Code:

echo "sudo mount -o loop $eFile $eMount" > syntax.txt
sudo mount -o loop $eFile $eMount &> error.log

Quote:

Originally Posted by dwhitney67 (Post 4362463)
The following works for a single ISO file that does not have white-space in the filename:

Thanks for sharing! But yea, the segment of code I'm debugging works fine for files without spaces so at this point I think there may be a bug in Nautilus or some developer secret that I'm not aware of that will allow escaped paths to work. As mentioned previously, this is a proof of concept for a customer considering linux implementation and renaming existing shared files is not an option.

Nominal Animal 05-21-2011 11:06 PM

Quote:

Originally Posted by thund3rstruck (Post 4361870)
Code:

echo "sudo mount -o loop $eFile $eMount" > syntax.txt
sudo mount -o loop $eFile $eMount &> error.log


Your latter command is wrong. It should be
Code:

sudo mount -o loop "$eFile" "$eMount" &> error.log
If you actually have somehow generated $eFile and $eMount with shell-special characters escaped with backslashes (which honestly I do not believe you have), don't. Use proper quoting instead.

If you quote the variables like I have, above, the variables may contain any characters that are valid in pathnames (i.e. anything except NULs or zero bytes), and the command will work. (It is possible sudo won't work, depending on your configuration, if you've redirected standard input and/or standard output, but that'd show up as a sudo error anyway.)

I work with files with all kinds of weird stuff in their names; sometimes with things that won't show up properly anywhere (like both UTF-8 and CP-1252 latin characters in the same file name). I can attest that if you always use double quotes with variable references, Bash scripts and Linux filesystem commands can handle any file name you can create. (The only exception I know of is when you must provide the file name in a string that is interpreted by a shell first. That case is solved by double-quoting the file name within the string, with a backslash added before ! " $ ` \ characters.)

thund3rstruck 05-21-2011 11:21 PM

Quote:

Originally Posted by Nominal Animal (Post 4363349)
Your latter command is wrong. It should be
Code:

sudo mount -o loop "$eFile" "$eMount" &> error.log
If you actually have somehow generated $eFile and $eMount with shell-special characters escaped with backslashes (which honestly I do not believe you have), don't. Use proper quoting instead.

If you quote the variables like I have, above, the variables may contain any...

Ugh...

So I did finally solve the mystery and it was all on me. The escaping/quoting was not the issue at all. It turned out that my call to the environmental variable $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS[0] resulted in a null terminator \0 character being sent to mount, following the first element (which mount didn't understand). This null terminator was not showing up in gEdit when echoing the command to execute to a file so this resulted in me being able to copy and paste from that file into the shell and the command getting executed successfully.

Thanks again everyone!


All times are GMT -5. The time now is 06:01 AM.