This commit is contained in:
gferg 2003-09-15 14:31:01 +00:00
parent 702659bde7
commit 22ceb88370
2 changed files with 84 additions and 0 deletions

View File

@ -0,0 +1,28 @@
#!/bin/bash
# script-array.sh: Loads this script into an array.
# Inspired by an e-mail from Chris Martin (thanks!).
script_contents=( $(cat "$0") ) # Stores contents of this script ($0)
#+ in an array.
for element in $(seq 0 $((${#script_contents[@]} - 1)))
do # ${#script_contents[@]}
#+ gives number of elements in the array.
#
# Question:
# Why is seq 0 necessary?
# Try changing it to seq 1.
echo -n "${script_contents[$element]}"
# List each field of this script on a single line.
echo -n " -- " # Use " -- " as a field separator.
done
echo
exit 0
# Exercise:
# --------
# Modify this script so it lists itself
#+ in its original format,
#+ complete with whitespace, line breaks, etc.

View File

@ -0,0 +1,56 @@
#!/bin/bash
# usrmnt.sh, written by Anthony Richardson
# Used with permission.
# usage: usrmnt.sh
# description: mount device, invoking user must be listed in the
# MNTUSERS group in the /etc/sudoers file.
# -----------------------------------------------------------------
# This is a usermount script that reruns
#+ itself using sudo. A user with the proper
#+ permissions only has to type
# usermount /dev/fd0 /mnt/floppy
# instead of
# sudo usermount /dev/fd0 /mnt/floppy
# I use this same technique for all of my
#+ sudo scripts, because I find it convenient.
# -----------------------------------------------------------------
# If SUDO_COMMAND variable is not set we are not being run through
#+ sudo, so rerun ourselves. Pass the user's real and group id . . .
if [ -z "$SUDO_COMMAND" ]
then
mntusr=$(id -u) grpusr=$(id -g) sudo $0 $*
exit 0
fi
# We will only get here if we are being run by sudo
/bin/mount $* -o uid=$mntusr,gid=$grpusr
exit 0
# Additional notes (from the author of this script):
# -------------------------------------------------
# 1) Linux allows the users option in the /etc/fstab
# file so that any user can mount removable media.
# But, on a server, I like to allow only a few
# individuals access to removable media. I find
# using sudo gives me more control.
# 2) I also find sudo to be more convenient than
# accomplishing this task through groups.
# 3) This method gives anyone with proper permissions
# root access to the mount command, so be careful
# about who you allow access. You can get finer
# control over which access can be mounted by using this
# same technique in separate mntfloppy, mntcdrom,
# and mntsamba scripts.