LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-20-2011, 09:01 AM   #1
thund3rstruck
Member
 
Registered: Nov 2005
Location: East Coast, USA
Distribution: Fedora 18, Slackware64 13.37, Windows 7/8
Posts: 346

Rep: Reputation: 38
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?
 
Old 05-20-2011, 09:11 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
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.
 
Old 05-20-2011, 09:21 AM   #3
thund3rstruck
Member
 
Registered: Nov 2005
Location: East Coast, USA
Distribution: Fedora 18, Slackware64 13.37, Windows 7/8
Posts: 346

Original Poster
Rep: Reputation: 38
Quote:
Originally Posted by druuna View Post
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!

Last edited by thund3rstruck; 05-20-2011 at 09:24 AM.
 
Old 05-20-2011, 06:46 PM   #4
Spatior
Member
 
Registered: Jun 2009
Location: México
Distribution: Suse, Debian based, CentOs
Posts: 48

Rep: Reputation: 10
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?
 
Old 05-20-2011, 09:12 PM   #5
thund3rstruck
Member
 
Registered: Nov 2005
Location: East Coast, USA
Distribution: Fedora 18, Slackware64 13.37, Windows 7/8
Posts: 346

Original Poster
Rep: Reputation: 38
Quote:
Originally Posted by Spatior View Post
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.
 
Old 05-20-2011, 10:55 PM   #6
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,523

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
Quote:
Originally Posted by thund3rstruck View Post
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.

Last edited by dwhitney67; 05-20-2011 at 10:58 PM.
 
Old 05-21-2011, 07:53 PM   #7
thund3rstruck
Member
 
Registered: Nov 2005
Location: East Coast, USA
Distribution: Fedora 18, Slackware64 13.37, Windows 7/8
Posts: 346

Original Poster
Rep: Reputation: 38
Quote:
Originally Posted by dwhitney67 View Post
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 View Post
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.
 
Old 05-21-2011, 11:06 PM   #8
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 943Reputation: 943Reputation: 943Reputation: 943Reputation: 943Reputation: 943Reputation: 943Reputation: 943
Quote:
Originally Posted by thund3rstruck View Post
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.)
 
Old 05-21-2011, 11:21 PM   #9
thund3rstruck
Member
 
Registered: Nov 2005
Location: East Coast, USA
Distribution: Fedora 18, Slackware64 13.37, Windows 7/8
Posts: 346

Original Poster
Rep: Reputation: 38
Quote:
Originally Posted by Nominal Animal View Post
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!

Last edited by thund3rstruck; 05-21-2011 at 11:53 PM. Reason: Solved - Update
 
  


Reply

Tags
bash scripting, nautilus


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] What does the following shell script expression mean? hyperfluid Programming 3 11-30-2010 04:55 PM
Using regular expression in expect script nik1984 Programming 1 08-28-2008 07:25 AM
script expression not running in cronjob dningale Solaris / OpenSolaris 2 08-13-2008 01:04 AM
rc script to mount filesystem not working? ginda Linux - Security 3 12-01-2006 08:28 PM
bash shell script expression CowboyJ Programming 2 04-25-2005 12:33 AM


All times are GMT -5. The time now is 11:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration