Skip to Main Content
Linux System Administration
book

Linux System Administration

by Tom Adelstein, Bill Lubanovic
March 2007
Intermediate to advanced content levelIntermediate to advanced
304 pages
11h 12m
English
O'Reilly Media, Inc.
Content preview from Linux System Administration
257
Appendix
APPENDIX
bash Script Samples
This appendix contains several scripts that can be useful to you in your daily work,
as well as serving as models for writing other scripts. You can download the scripts
from http://www.centralsoft.org.
Adding Users
If you have a lot of turnover (such as in a university, where new students enter in
bunches once or several times a year), this script can help you add them to your sys-
tem quickly. It reads a file listing information about each user and invokes useradd
with the proper arguments (see the section “User Management” in Chapter 8 for
details about useradd and its variants):
#!/bin/bash
expiredate=2009-02-18
if [[ -z "$1" ]] ; then
echo ""
echo "Please give exactly one file name."
echo "The file will have one user per line."
echo "Each line will have:"
echo " username"
echo " group"
echo " personal real name"
echo ""
echo "Sample line:
echo "alfredo marketing Alfredo de Darc"
exit 1
fi
cat "$1" | while read username groupname realname
do
# Skip blank lines.
if [[ -z $username || -z $groupname || -z $realname ]]; then
continue
fi
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Linux System Administration

Mastering Linux System Administration

Christine Bresnahan, Richard Blum
Mastering Linux Administration

Mastering Linux Administration

Alexandru Calcatinge, Julian Balog

Publisher Resources

ISBN: 9780596009526Supplemental ContentCatalog PageErrata