LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora
User Name
Password
Fedora This forum is for the discussion of the Fedora Project.

Notices


Reply
  Search this Thread
Old 02-15-2009, 10:36 PM   #1
terry-duell
Member
 
Registered: Jan 2007
Location: Melbourne, Australia
Distribution: Fedora 38 x86_64
Posts: 539

Rep: Reputation: 59
How to run a root command from script?


Hullo All,
I am playing about with Fedora10 installed in VirtualBox on a Fedora9 x86_64 system.
To mount a shared folder I need to run a command as root, which works OK, if done the right way.
I thought it might be simpler to do it via a shell script, but that doesn't work and neither does the use of sudo, or su. The only way I have managed to get it to work without error is to use 'su -'
Here is the response I got from the terminal...

[terry@localhost ~]$ sudo mount -t vboxsf -o uid=terry ShareVM /home/terry/ShareVM
/sbin/mount.vboxsf: mounting failed with the error: Protocol error
[terry@localhost ~]$ su
Password:
[root@localhost terry]# mount -t vboxsf -o uid=terry ShareVM /home/terry/ShareVM
/sbin/mount.vboxsf: mounting failed with the error: Protocol error
[root@localhost terry]# exit
exit
[terry@localhost ~]$ su -
Password:
[root@localhost ~]# mount -t vboxsf -o uid=terry ShareVM /home/terry/ShareVM
[root@localhost ~]#

here is the script that doesn't work...

#! /bin/sh
# this script sets up the share directory
sudo mount -t vboxsf -o uid=terry ShareVM /home/terry/ShareVM

Can someone please point me in the right direction on this?

Cheers,
Terry
 
Old 02-15-2009, 11:58 PM   #2
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
Maybe try sudo su - -c 'mount -t vboxsf -o uid=terry ShareVM /home/terry/ShareVM'
 
Old 02-16-2009, 03:55 PM   #3
terry-duell
Member
 
Registered: Jan 2007
Location: Melbourne, Australia
Distribution: Fedora 38 x86_64
Posts: 539

Original Poster
Rep: Reputation: 59
Quote:
Originally Posted by raskin View Post
Maybe try sudo su - -c 'mount -t vboxsf -o uid=terry ShareVM /home/terry/ShareVM'
Wonderful!
That worked like a bought one.

Many thanks.

Cheers,
Terry
 
  


Reply



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
How to run a shell script as root (when user is not root) taylorkh Linux - Newbie 10 09-12-2008 06:05 PM
Want to run script without being root, possible? webaccounts Linux - Newbie 8 06-11-2008 08:52 PM
How can I have a script owned as root and run as root by a user: setuid? stickey bit? abefroman Linux - Newbie 9 04-19-2008 05:15 PM
why lftp command run failed when user isn't root, but ok when logining as root steven_yu Linux - Software 0 06-06-2007 08:36 PM
Is a script, run at boot time from init.d, run with root authority? tmbrwolf53 Linux - Server 2 03-31-2007 08:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora

All times are GMT -5. The time now is 03:57 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
Open Source Consulting | Domain Registration