I am running a script to check for security vulnerabilities. How do I add a timestamp to the script with results going into a file in /var/log/security-check
#!/bin/sh
# watch accounts - keep an eye on /etc/passwd,
# report if accounts change
secretcopy="$HOME/.watchdb"
tempfile="$HOME/.watchdb.new"
passwd="/etc/passwd"
compare=0 # by default, don't compare
trap "/bin/rm -f $tempfile" 0
if [ -s "$secretcopy" ] ; then
lastrev="$(cat $secretcopy)"
compare=1
fi
cat $passwd | cut -d: -f1 > $tempfile
current="$(cat $tempfile)"
if [ $compare -eq 1 ] ; then
if [ "$current" != "$lastrev" ] ; then
echo "WARNING: password file has changed"
diff $secretcopy $tempfile | grep '^[<>]' |
sed 's/</Removed: /;s/>/Added:/'
fi
else
mv $tempfile $secretcopy
fi
exit 0
echo $(date) >> /var/log/security-check.ls -lto check that. Also if you need to timestamp any file, just usetouch.touch <script_name>creates if it doesn’t exist. If it exists, timestamp of that script that you passed to it will be updated to latest time.data >>/var/log/cecurity-checkwould do as well.