Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #170661

Using sudo in a script.

From Ken Heard <kenslists@teksavvy.com>
Newsgroups linux.debian.user
Subject Using sudo in a script.
Date 2016-08-03 18:40 +0200
Message-ID <s27n9-4Sd-41@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


-----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-----

Back to linux.debian.user | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Using sudo in a script. Ken Heard <kenslists@teksavvy.com> - 2016-08-03 18:40 +0200
  Re: Using sudo in a script. Don Armstrong <don@debian.org> - 2016-08-03 19:30 +0200
  Re: Using sudo in a script. Ken Heard <kenslists@teksavvy.com> - 2016-08-03 23:30 +0200
  Re: Using sudo in a script. Ken Heard <kenslists@teksavvy.com> - 2016-08-03 23:30 +0200
    Re: Using sudo in a script. deloptes <deloptes@gmail.com> - 2016-08-04 02:10 +0200

csiph-web