Re: Using sudo in a script.

2016-08-03 Thread deloptes
Ken Heard wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> On 2016-08-03 15:16, Jude DaShiell wrote:
>> Why not try a -H switch on the sudo line in your script and see
>> what happens?
> 
> I did.  The answer was nothing.

why bother users run sudo commands when they can use the desktop
functionality and transparently mount/umount whatever they attach to the
system and is not in fstab






Re: Using sudo in a script.

2016-08-03 Thread Ken Heard
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 2016-08-03 15:16, Jude DaShiell wrote:
> Why not try a -H switch on the sudo line in your script and see
> what happens?

I did.  The answer was nothing.

Regards, Ken

-BEGIN PGP SIGNATURE-
Version: GnuPG v2

iEYEARECAAYFAleiYfsACgkQlNlJzOkJmTcD7wCbB/PgXclQY8xzuUAov+I37DaR
2qUAnj8XHWQADZzDmIyB6QopXDRsMYaO
=6LWe
-END PGP SIGNATURE-



Re: Using sudo in a script.

2016-08-03 Thread Ken Heard
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 2016-08-03 12:21, Ken Heard wrote:
> I would like to create a short script to mount and unmount SCXC
> cards. For these exfat cards to do either in Jessie has to be done
> as root.
> 
> I have set up sudo so that my user can run any command as root.
> the following command will mount the card without asking for my
> password.
> 
> sudo mount -U 6238-3434 /media/xca
> 
> (My file /etc/fstab contains the following line:
> 
> UUID-6238-3434  /media/xca  exfat   rw,users,noauto,noatime 0
> 0)
> 
> In order to automate the process I wrote the following script named
> mxca :
> 
> #!/bin/bash # Script to mount xca from any directory. CURPWD=$PWD 
> cd /home/ken sudo mount -U 6238-3434 /media/xca cd $CURPWD
> 
> Running mxca alone does not produce the required result.  Running
> sudo mxca together however does, even though the sudo command is
> also in the script.
> 
> I can unmount the card by running command sudo umount /media/xca,
> but I would like a similar script named uxca to do the same thing
> for unmounting.
> 
> Is there a way to make sudo do its thing in these scripts so that
> I can mount and unmount the SDXC card by running the script
> commands mxca and uxca by themselves?

I have since discovered a command "/sbin/mount.fuse" and "fusermount
- -u" which are supposed to allow a non-privileged user to mount and
unmount exfat devices; but I haven't figured out how to use them yet.
 A simple "/sbin/mount.fuse /media/xca" or "fusermount -u /media/xca"
do not work.  Other than fixing the format of the UUID device indicate
from UUID- to UUID= I have yet to experiment with Don Armstrong's
other suggestions.  I thing I would rather get /sbin/mount.fuse and
fusermount -u to work instead.

Regards, Ken


-BEGIN PGP SIGNATURE-
Version: GnuPG v2

iEYEARECAAYFAleiYSoACgkQlNlJzOkJmTe4fwCcDvq8eBcq0I7guGdmmhN23sgP
3KEAn0LJKJzJUlIJTD0jMMt3T4CyXWAw
=lclv
-END PGP SIGNATURE-



Re: Using sudo in a script.

2016-08-03 Thread Don Armstrong
On Wed, 03 Aug 2016, Ken Heard wrote:

> I would like to create a short script to mount and unmount SCXC cards.
>  For these exfat cards to do either in Jessie has to be done as root.
> 
> I have set up sudo so that my user can run any command as root.  the
> following command will mount the card without asking for my password.
> 
> sudo mount -U 6238-3434 /media/xca
> 
> (My file /etc/fstab contains the following line:
> 
> UUID-6238-3434  /media/xca  exfat   rw,users,noauto,noatime 0 0)

This should probably be

UUID=6238-3434 /media/xca exfat rw,users.noauto,noatime 0 0

and then in theory you should be able to go

mount /media/xca

as a user. If not, this sounds like a bug in mount.exfat.

> In order to automate the process I wrote the following script named mxca
> :
> 
> #!/bin/bash
> # Script to mount xca from any directory.
> CURPWD=$PWD
> cd /home/ken
> sudo mount -U 6238-3434 /media/xca
> cd $CURPWD

First off, the cd in the script won't change what the directory is once
the subshell started for the script exits.

Second, if you need to change directories temporarily in a shell script,
use a subshell:

#!/bin/bash
(cd /home/ken;
 sudo mount -U 6238-3434 /media/xca;
)

> Is there a way to make sudo do its thing in these scripts so that I
> can mount and unmount the SDXC card by running the script commands
> mxca and uxca by themselves?

It's possible that sudo doesn't have a tty, and can't ask for a
password. adding set -x; early on in the script may help you see what is
actually happening.

-- 
Don Armstrong  https://www.donarmstrong.com

Those who begin coercive elimination of dissent soon find themselves
exterminating dissenters. Compulsory unification of opinion achieves
only the unanimity of the graveyard.
 -- Justice Roberts in 319 U.S. 624 (1943)



Using sudo in a script.

2016-08-03 Thread Ken Heard
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

I would like to create a short script to mount and unmount SCXC cards.
 For these exfat cards to do either in Jessie has to be done as root.

I have set up sudo so that my user can run any command as root.  the
following command will mount the card without asking for my password.

sudo mount -U 6238-3434 /media/xca

(My file /etc/fstab contains the following line:

UUID-6238-3434  /media/xca  exfat   rw,users,noauto,noatime 0 0)

In order to automate the process I wrote the following script named mxca
:

#!/bin/bash
# Script to mount xca from any directory.
CURPWD=$PWD
cd /home/ken
sudo mount -U 6238-3434 /media/xca
cd $CURPWD

Running mxca alone does not produce the required result.  Running sudo
mxca together however does, even though the sudo command is also in
the script.

I can unmount the card by running command sudo umount /media/xca, but
I would like a similar script named uxca to do the same thing for
unmounting.

Is there a way to make sudo do its thing in these scripts so that I
can mount and unmount the SDXC card by running the script commands
mxca and uxca by themselves?

Regards, Ken Heard


-BEGIN PGP SIGNATURE-
Version: GnuPG v2

iEYEARECAAYFAleiGgQACgkQlNlJzOkJmTeE9ACfaJZ3Fk27+a9YPhHtk040cCpF
D/QAnA7KuGGRMlkP3AIpHqUiTgtyaaq2
=cxii
-END PGP SIGNATURE-



Re: using SUDO in bash script

2004-02-05 Thread Michael Rauch
Rick Weinbender wrote:
Adam Aube wrote:


On Wednesday 04 February 2004 03:23 pm, Rick Weinbender wrote:

Can I use SUDO within a bash script?
Absolutely, though be aware that if sudo is set to require a password, you
won't be able to run it in the background.
By putting NOPASSWD before the command in /etc/sudoers, sudo will not
require a password to run that command.


*

Thanks.
I'm new to SUDO, but I found a web clip that seems to be
what I'm going for.  Just can't make it work yet.
Can I avoid typing sudo before myprogram at the commandline?
Clip Below:
*
Clipped from article:
The one disadvantage of using sudo is that your users have to
 remember to run sudo ... as part of their command.  However,
 that's easy to work around by simply creating a wrapper shell
 script.  This is a normal (non-SUID) shell script that simply does
 something like:
``
#!/bin/sh
exec /usr/bin/sudo /some/path/to/our/target/prog $@
''
 (execute sudo, on the target program and pass our argument,
 preserving any quoting as we specified it).
*
Thanks,
-Rick
instead of writing a shellscript you could also use aliases in the bash
shell (don't know if it works in other shells though). to have your
aliases available all the time, you can but them in your .bashrc file in
your $HOME directory (you will probably already find some aliases
defined in there).
example:
$ alias ls='cd'
doesn't make much sense, but shows you how it works: ls is now defined
as an alias for cd. so if you type 'ls /home' bash will actually invoke
'cd /home'
similar you could use:
$ alias myprogram='sudo myprogram'
to make bash invoke myprogram with SUDO

hth
#!mike


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: using SUDO in bash script

2004-02-05 Thread Kent West
Michael Rauch wrote:

instead of writing a shellscript you could also use aliases in the bash
shell (don't know if it works in other shells though). to have your
aliases available all the time, you can but them in your .bashrc file in
your $HOME directory (you will probably already find some aliases
defined in there).
example:
$ alias ls='cd'
doesn't make much sense, but shows you how it works: ls is now defined
as an alias for cd. so if you type 'ls /home' bash will actually invoke
'cd /home'
And of course, if you try this experiment, you'll want to be aware of 
the unalias command.

$ unalias ls

will undo the above alias.

$ alias

will show you your current aliases.

--
Kent
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: using SUDO in bash script

2004-02-05 Thread Micha Feigin
On Thu, Feb 05, 2004 at 01:41:43PM +0100, Michael Rauch wrote:
 Rick Weinbender wrote:
 Adam Aube wrote:
 
 
 On Wednesday 04 February 2004 03:23 pm, Rick Weinbender wrote:
 
 Can I use SUDO within a bash script?
 
 Absolutely, though be aware that if sudo is set to require a password, you
 won't be able to run it in the background.
 
 By putting NOPASSWD before the command in /etc/sudoers, sudo will not
 require a password to run that command.
 
 
 
 *
 
 Thanks.
 I'm new to SUDO, but I found a web clip that seems to be
 what I'm going for.  Just can't make it work yet.
 Can I avoid typing sudo before myprogram at the commandline?
 
 Clip Below:
 *
 Clipped from article:
 The one disadvantage of using sudo is that your users have to
  remember to run sudo ... as part of their command.  However,
  that's easy to work around by simply creating a wrapper shell
  script.  This is a normal (non-SUID) shell script that simply does
  something like:
 ``
 #!/bin/sh
 exec /usr/bin/sudo /some/path/to/our/target/prog $@
 ''
  (execute sudo, on the target program and pass our argument,
  preserving any quoting as we specified it).
 *
 

This clip is what you want to do.

Save that shell script as the program name to run, for example save it
as

sudoprog

and give it executable permitions (chmod +x). When you users now run
sudoprog it will run the shell script that will call the program using
sudo. This will still ask for the password if sudo is setup to ask for
a password (very recomended).
Another option which is much less secure is to set the program setuid root
which will make it run as the root even when a normal user runs it (it
actually runs the program as the owner which in this case is root).
you need to make it owned by root and then run chmod 04755 prog. This
will give you no access control though so watch out. (you can also
limit the access a bit using group limitation by doing 
chgrp prog group prog and then chmod 04750 prog)
The advantage of sudo is that you can set a per user and per program
access settings.

 Thanks,
 -Rick
 
 instead of writing a shellscript you could also use aliases in the bash
 shell (don't know if it works in other shells though). to have your
 aliases available all the time, you can but them in your .bashrc file in
 your $HOME directory (you will probably already find some aliases
 defined in there).
 
 example:
 $ alias ls='cd'
 
 doesn't make much sense, but shows you how it works: ls is now defined
 as an alias for cd. so if you type 'ls /home' bash will actually invoke
 'cd /home'
 
 similar you could use:
 $ alias myprogram='sudo myprogram'
 
 to make bash invoke myprogram with SUDO
 
 hth
 #!mike
 
 
 
 
 -- 
 To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
 with a subject of unsubscribe. Trouble? Contact 
 [EMAIL PROTECTED]
 
 
 +++
 This Mail Was Scanned By Mail-seCure System
 at the Tel-Aviv University CC.
 


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: using SUDO in bash script

2004-02-05 Thread Rick Weinbender
Micha Feigin wrote:

 On Thu, Feb 05, 2004 at 01:41:43PM +0100, Michael Rauch wrote:
  Rick Weinbender wrote:
  Adam Aube wrote:
  
  On Wednesday 04 February 2004 03:23 pm, Rick Weinbender wrote:
  Can I use SUDO within a bash script?
  
  Absolutely, though be aware that if sudo is set to require a password, you
  won't be able to run it in the background.
  By putting NOPASSWD before the command in /etc/sudoers, sudo will not
  require a password to run that command.
  *
  Thanks.
  I'm new to SUDO, but I found a web clip that seems to be
  what I'm going for.  Just can't make it work yet.
  Can I avoid typing sudo before myprogram at the commandline?
  
  Clip Below:
  *
  Clipped from article:
  The one disadvantage of using sudo is that your users have to
   remember to run sudo ... as part of their command.  However,
   that's easy to work around by simply creating a wrapper shell
   script.  This is a normal (non-SUID) shell script that simply does
   something like:
  ``
  #!/bin/sh
  exec /usr/bin/sudo /some/path/to/our/target/prog $@
  ''
   (execute sudo, on the target program and pass our argument,
   preserving any quoting as we specified it).
  *
  

 This clip is what you want to do.

 Save that shell script as the program name to run, for example save it
 as

 sudoprog

 and give it executable permitions (chmod +x). When you users now run
 sudoprog it will run the shell script that will call the program using
 sudo. This will still ask for the password if sudo is setup to ask for
 a password (very recomended).
 Another option which is much less secure is to set the program setuid root
 which will make it run as the root even when a normal user runs it (it
 actually runs the program as the owner which in this case is root).
 you need to make it owned by root and then run chmod 04755 prog. This
 will give you no access control though so watch out. (you can also
 limit the access a bit using group limitation by doing
 chgrp prog group prog and then chmod 04750 prog)
 The advantage of sudo is that you can set a per user and per program
 access settings.

  Thanks,
  -Rick
 
  instead of writing a shellscript you could also use aliases in the bash
  shell (don't know if it works in other shells though). to have your
  aliases available all the time, you can but them in your .bashrc file in
  your $HOME directory (you will probably already find some aliases
  defined in there).
 
  example:
  $ alias ls='cd'
 
  doesn't make much sense, but shows you how it works: ls is now defined
  as an alias for cd. so if you type 'ls /home' bash will actually invoke
  'cd /home'
 
  similar you could use:
  $ alias myprogram='sudo myprogram'
 
  to make bash invoke myprogram with SUDO
 
  hth
  #!mike

***

Thanks to everyone for the help!
-Rick


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



using SUDO in bash script

2004-02-04 Thread Rick Weinbender
Can I use SUDO within a bash script?
ie:
#!/bin/sh
sudo myprogram

Thanks,
-Rick



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: using SUDO in bash script

2004-02-04 Thread Adam Aube
On Wednesday 04 February 2004 03:23 pm, Rick Weinbender wrote:
 Can I use SUDO within a bash script?

Absolutely, though be aware that if sudo is set to require a password, you 
won't be able to run it in the background.

By putting NOPASSWD before the command in /etc/sudoers, sudo will not 
require a password to run that command.

Adam


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: using SUDO in bash script

2004-02-04 Thread Rick Weinbender
Adam Aube wrote:

 On Wednesday 04 February 2004 03:23 pm, Rick Weinbender wrote:
  Can I use SUDO within a bash script?

 Absolutely, though be aware that if sudo is set to require a password, you
 won't be able to run it in the background.

 By putting NOPASSWD before the command in /etc/sudoers, sudo will not
 require a password to run that command.


*

Thanks.
I'm new to SUDO, but I found a web clip that seems to be
what I'm going for.  Just can't make it work yet.
Can I avoid typing sudo before myprogram at the commandline?

Clip Below:
*
Clipped from article:
The one disadvantage of using sudo is that your users have to
 remember to run sudo ... as part of their command.  However,
 that's easy to work around by simply creating a wrapper shell
 script.  This is a normal (non-SUID) shell script that simply does
 something like:
``
#!/bin/sh
exec /usr/bin/sudo /some/path/to/our/target/prog $@
''
 (execute sudo, on the target program and pass our argument,
 preserving any quoting as we specified it).
*

Thanks,
-Rick



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: using SUDO in bash script

2004-02-04 Thread Adam Aube
On Wednesday 04 February 2004 04:09 pm, Rick Weinbender wrote:
 Can I avoid typing sudo before myprogram at the commandline?

Yes - it works just like the article you quoted describes it.

Adam


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]