LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Fedora (https://www.linuxquestions.org/questions/fedora-35/)
-   -   How to run a root command from script? (https://www.linuxquestions.org/questions/fedora-35/how-to-run-a-root-command-from-script-704924/)

terry-duell 02-15-2009 10:36 PM

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

raskin 02-15-2009 11:58 PM

Maybe try sudo su - -c 'mount -t vboxsf -o uid=terry ShareVM /home/terry/ShareVM'

terry-duell 02-16-2009 03:55 PM

Quote:

Originally Posted by raskin (Post 3444982)
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


All times are GMT -5. The time now is 09:33 PM.