Code:
#! /bin/bash
echo -n "File: ";read n;filename=$n
echo -n "Delay: ";read n;delay=$n
echo -n "Write to file? y/n: "read n
if [ "$n" = "y" ]
then
echo -n "What file do you want to write to?: "
read n
wfile=$n
else
echo "WARNING: If you are running this in another terminal, you will not receive output on deletion time. Unless you write to a file"
fi
if [[ -a $filename ]]
then
until [[ ! -a $filename ]]
do
echo "$filename exists"
sleep $delay
done
fi
[[ -a $filename ]] || output="$filename was renamed/removed at `date`";echo $output
if [ $wfile ];then echo $output >> $wfile;fi
now generally I would run this as "xterm -e monitor &" and whenever the script ends (Loop breaks) I would like it to output $output to the main terminal. Would knowing the PID of the terminal I want to pipe it to have something to do with this? Also any critiques on my script would be helpful.
(I use this script for Cyber-Patriot competitions where people are trying to break into the system and monitoring system files is very helpful, also the reason the script is spaced oddly is because im recreating it from memory, and im tired :|)