COMP 266 Lecture Notes - Lecture 5: Awk, Shell Script, Grep

33 views1 pages
Lab 5
1. Write a shell script to help monitor the health of your /etc/passwd file.
a. Find entries that have UID 0.
b. Find entries that have that have no password (needs /etc/shadow).
c. Find any sets of entries that have duplicate UIDs.
d. Find entries that have duplicate login names.
e. Find entries that have no expiration date (needs /etc/shadow).
Ans:
#!/bin/sh
#Find entries that have UID 0
echo "Checking for entries with root uid 0"
awk -F: '$3 = "0" {print "found " $0}' /etc/passwd
#Find entries that have no password (use /etc/shadow)
echo "Total amount of entries without passwords:"
grep -Ec '\!|\*' /etc/shadow
#Find sets of entries with duplicate UIDs
echo "Check for duplicate UID's..."
awk -F: 'uname[$3]++ && uname[$3]>1 {print "duplicate user:", $1} ' /etc/passwd
echo "Duplicate UID check done"
#Find entries with duplicate login names
echo "Check for duplicate user names..."
awk -F: 'uid[$3]++ && uid[$3]>1 {print "duplicate uid:", $3}' /etc/passwd
echo "Duplicate user name check done."
#Find entries with no expiration date (use /etc/shadow)
echo "Checking for entries with no expiration date (set to 99999)"
awk '{ FS = ":" } { if ( $5 == 99999) { print $1 " has expiration set to " $5} }' /etc/shadow
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows half of the first page of the document.
Unlock all 1 pages and 3 million more documents.

Already have an account? Log in

Document Summary

#find entries that have uid 0 echo "checking for entries with root uid 0" awk -f: " = "0" {print "found " sh}" /etc/passwd. #find entries that have no password (use /etc/shadow) echo "total amount of entries without passwords:" grep -ec "\!|\*" /etc/shadow. #find sets of entries with duplicate uids echo "check for duplicate uid"s" awk -f: "uname[]++ && uname[]>1 {print "duplicate user:", } " /etc/passwd echo "duplicate uid check done" #find entries with duplicate login names echo "check for duplicate user names" awk -f: "uid[]++ && uid[]>1 {print "duplicate uid:", }" /etc/passwd echo "duplicate user name check done. "

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents