#!/bin/bash
#		       /usr/local/bin/newest
# http://crystalfaeries.net/posix/bin/newest
# celeste:crystalfaery NEWEST 2017-02-06 00:38:35+00:00
# Edit the newest files we usually manage manually
# COULD WE NOT COMBINE oldest and newest TOGETHER IN ONE SCRIPT HARDLINKED?

#	INITIALIZATION
cd $HOME
exitval=1
appname="$(basename $0)"
tmpfile="$(mktemp /tmp/${appname}.XXXXXX)" || exit 1
trap "let exitval=$?; rm -f $tmpfile; exit $exitval" 0 1 2 15
cp /dev/null "$tmpfile"				# clear our temp file

#	FIND OUR TARGET FILES
# logs designated to be monitored:
if [ \! -r /home/`whoami`/.monitor.txt ]
then	# install default log monitoring file:
	echo /home/downloads/youtube.com/.youlog.txt	>> /home/`whoami`/.monitor.txt
	echo /usr/local/share/ag/silverlog.txt		>> /home/`whoami`/.monitor.txt
	echo /var/log/apache2/access.log		>> /home/`whoami`/.monitor.txt
	echo /var/log/apache2/error.log			>> /home/`whoami`/.monitor.txt
	echo /var/log/apache2/other_vhosts_access.log	>> /home/`whoami`/.monitor.txt
	echo /var/log/chronicle.log			>> /home/`whoami`/.monitor.txt
	echo /var/log/darchive.log			>> /home/`whoami`/.monitor.txt
	echo /var/log/dar.log				>> /home/`whoami`/.monitor.txt
	echo /var/log/denyhosts				>> /home/`whoami`/.monitor.txt
	echo /var/log/feed2imap.log			>> /home/`whoami`/.monitor.txt
	echo /var/log/messages				>> /home/`whoami`/.monitor.txt
	echo /var/log/rsnapshot.log			>> /home/`whoami`/.monitor.txt
	echo /var/log/silver.log			>> /home/`whoami`/.monitor.txt
	echo /var/log/syncup.log			>> /home/`whoami`/.monitor.txt
	echo /var/log/vsftpd.log			>> /home/`whoami`/.monitor.txt
	vi						   /home/`whoami`/.monitor.txt || exit 254
fi
echo							   /home/`whoami`/.monitor.txt	>>	"$tmpfile"
cat							   /home/`whoami`/.monitor.txt	>>	"$tmpfile"
# script files
/usr/local/bin/name_tidy /usr/local/bin
# nice ionice -c 3 find /usr/local/bin/	-type f 2>/dev/null				>>	"$tmpfile"
nice find /usr/local/bin/	-type f 2>/dev/null				>>	"$tmpfile"
# text and web pages
/usr/local/bin/synctxt
for d in /usr/local/doc/txt/ /usr/local/src/txt/ /home/crystalfaeries.net/src
do
	/usr/local/bin/name_tidy $d
# 	nice ionice -c 3 find "$d"/ \( -iname ".*.txt"  -o -iname  "*.txt"  -o -iname ".*.htm*" -o -iname  "*.htm*" \) >> "$tmpfile"
	nice find "$d"/ \( -iname ".*.txt"  -o -iname  "*.txt"  -o -iname ".*.htm*" -o -iname  "*.htm*" \) >> "$tmpfile"
done

# edit from newest to oldest
vi $(ls -t  $(sort -u "$tmpfile"))
exitval=$?
exit $exitval


syntax highlighted by Code2HTML, v. 0.9.1