Hello guys.
I've recently written a basic utilities script just for home use.
and i want to attach a logfile to it that will record all the commands that where executed in that script. Then just so i can add the d%b%y% and make each logfile unique and i can look back in each logfile to see what i did.
I no it can be done i did it a long time back but have totally forgotten.
#!/bin/bash
while :
do
clear
echo " M A I N - M E N U"
echo "1. Make a New Directory"
echo "2. Safely Delete a File"
echo "3. List Out the Contents of a File"
echo "4. Display the Full name of Any User"
echo "5. Display The Current Date"
echo "6. Display the Disk Usage"
echo "7. Show who is logged on"
echo "8. Show User Processes"
echo "9. Display The logfile"
echo "0. Exit"
echo -n "Please enter option [0 - 9]"
read opt
case $opt in
1) 'pwd'
echo "The Above Directory is where your file will be created.";
echo "Make a New Directory, Enter a New DIR NAME please $USER";
read "dir_name";
mkdir "$dir_name";
echo "Press Enter key to Continue";
read enterKey;;
2) "$(ls -l)"
echo "Which File Do you want to delete?";
read fname;
if [ -d $fname ];
then echo "Sorry But this file is a Directory and Must be deleted Manually";
fi;
if [ -f $fname ];
then
cp $fname /home/$USER/dsave/$fname$$;
fi;
rm -r "$fname"
echo "Please press the enter Key to continue..."
read enterKey;;
3) "$(ls -l)"
echo "Which File Do you want list the Contents of?";
read response2;
ls -l "$response2";
echo "Press Enter Key To Continue";
read enterKey;;
4) echo "Listing all Users now";
cat /etc/passwd | grep "/home" |cut -d: -f1
echo "All users have now been Printed";
echo "Press Enter Key to continue";
read enterKey;;
5) echo " Todays date and time is '$(date)'";
echo " Press the Enterkey to Continue";
read enterKey;;
6) "$(df -ah)";
echo " Press the Enterkey to continue";
read enterKey;;
7) echo "This Is Who Is Currently Logged";
who | more;
echo "Please press enter key to continue..";
read enterKey;;
8) echo "Displaying all processes for Users";
"$(ps -afu)";
echo "Press the Enterkey to continue";
read enterKey;;
# 9) LOGFILE=/home/$USER/logfiles/`date '+%d%b%y'`.logfile.log;;
0) echo "GoodBye";
exit l;;
esac
done
So where abouts would i redirect it to the logfile?
And what kind of options is it going to record, Just the text on the line?
Theres no way of recording everything that goes on in this script simply..
.
.
.
1) 'pwd'
echo "The Above Directory is where your file will be created."; >> /home/
echo "Make a New Directory, Enter a New DIR NAME please $USER";
read "dir_name";
echo mkdir "$dir_name" >> logfile
mkdir "$dir_name";
echo "Press Enter key to Continue";
read enterKey;;
2) "$(ls -l)"
echo "Which File Do you want to delete?";
read fname;
if [ -d $fname ];
then echo "Sorry But this file is a Directory and Must be deleted Manually";
fi;
if [ -f $fname ];
then
cp $fname /home/$USER/dsave/$fname$$;
fi;
rm -r "$fname"
echo rm -r "$fname" >> logfile
echo "Please press the enter Key to continue..."
read enterKey;;
.
.
.