![]() | 1 | initial version |
Minors changes, ';' 'sh to bash'
#!/bin/bash
# acctchk.sh
# This script compares the current /etc/passwd file against an archived copy called /root/passed.ar. # It produces a list of added or deleted accounts. It creates an archived file from /etc/passwd
# called /root/passwd.ar if none exists.
cd /root
if [ -f /root/passwd.ar ]; then
echo “Today is `date`” # print today’s date
sort </etc/passwd > ./tmp1 # sort the contents of the /etc/passwd file into tmp1
sort </root/passwd.ar> ./tmp2 # sort the contents of the /root/passwd.ar file into tmp2
echo “*** Accounts added:”
comm -23 ./tmp1 ./tmp2 # output any lines that are in tmp1 but not in tmp2 (added accounts)
echo “*** Accounts deleted:”
comm -13 ./tmp1 ./tmp2 # output any lines that are in tmp2 but not in tmp1 (deleted accounts)
echo “”
rm –f ./tmp1 ./tmp2 # remove temporary files
else
echo “** Creating archived /etc/passwd file ** “
cp /etc/passwd /root/passwd.ar # create the archive if it doesn’t already exist
fi
![]() | 2 | No.2 Revision |
Minors changes, ';' 'then;' other 'sh to bash'
#!/bin/bash
# acctchk.sh
# This script compares the current /etc/passwd file against an archived copy called /root/passed.ar. # It produces a list of added or deleted accounts. It creates an archived file from /etc/passwd
# called /root/passwd.ar if none exists.
cd /root
if [ -f /root/passwd.ar ]; then
echo “Today is `date`” # print today’s date
sort </etc/passwd > ./tmp1 # sort the contents of the /etc/passwd file into tmp1
sort </root/passwd.ar> ./tmp2 # sort the contents of the /root/passwd.ar file into tmp2
echo “*** Accounts added:”
comm -23 ./tmp1 ./tmp2 # output any lines that are in tmp1 but not in tmp2 (added accounts)
echo “*** Accounts deleted:”
comm -13 ./tmp1 ./tmp2 # output any lines that are in tmp2 but not in tmp1 (deleted accounts)
echo “”
rm –f ./tmp1 ./tmp2 # remove temporary files
else
echo “** Creating archived /etc/passwd file ** “
cp /etc/passwd /root/passwd.ar # create the archive if it doesn’t already exist
fi
![]() | 3 | No.3 Revision |
Minors changes, 'then;' other 'sh to bash'bash' I share you a great guide about conditionals (if statements).
#!/bin/bash
# acctchk.sh
# This script compares the current /etc/passwd file against an archived copy called /root/passed.ar. # It produces a list of added or deleted accounts. It creates an archived file from /etc/passwd
# called /root/passwd.ar if none exists.
cd /root
if [ -f /root/passwd.ar ]; then
echo “Today is `date`” # print today’s date
sort </etc/passwd > ./tmp1 # sort the contents of the /etc/passwd file into tmp1
sort </root/passwd.ar> ./tmp2 # sort the contents of the /root/passwd.ar file into tmp2
echo “*** Accounts added:”
comm -23 ./tmp1 ./tmp2 # output any lines that are in tmp1 but not in tmp2 (added accounts)
echo “*** Accounts deleted:”
comm -13 ./tmp1 ./tmp2 # output any lines that are in tmp2 but not in tmp1 (deleted accounts)
echo “”
rm –f ./tmp1 ./tmp2 # remove temporary files
else
echo “** Creating archived /etc/passwd file ** “
cp /etc/passwd /root/passwd.ar # create the archive if it doesn’t already exist
fi
![]() | 4 | No.4 Revision |
Minors changes, 'then;' '; then' other 'sh to bash' I share you a great guide about conditionals (if statements).
#!/bin/bash
# acctchk.sh
# This script compares the current /etc/passwd file against an archived copy called /root/passed.ar. # It produces a list of added or deleted accounts. It creates an archived file from /etc/passwd
# called /root/passwd.ar if none exists.
cd /root
if [ -f /root/passwd.ar ]; then
echo “Today is `date`” # print today’s date
sort </etc/passwd > ./tmp1 # sort the contents of the /etc/passwd file into tmp1
sort </root/passwd.ar> ./tmp2 # sort the contents of the /root/passwd.ar file into tmp2
echo “*** Accounts added:”
comm -23 ./tmp1 ./tmp2 # output any lines that are in tmp1 but not in tmp2 (added accounts)
echo “*** Accounts deleted:”
comm -13 ./tmp1 ./tmp2 # output any lines that are in tmp2 but not in tmp1 (deleted accounts)
echo “”
rm –f ./tmp1 ./tmp2 # remove temporary files
else
echo “** Creating archived /etc/passwd file ** “
cp /etc/passwd /root/passwd.ar # create the archive if it doesn’t already exist
fi