Ok, here is what I have so far, but I am still pretty lost I think.
I'm still very much new to Bash and Unix.
#!/bin/bash
n=1
while read curline; do
lasttasks[$n]=${curline}
((n++))
done < ~/.tasklog
if [ $n -le "6" ]; then
n=6
fi
echo "Hi, Name Here"
for ((i=n-5;i<n;i++))
do
printf "%s\n" "${lasttasks}"
done
echo "What do you plan on doing today?"
read myproj
mydate=`date +"%D %T"`
printf "%s: %s\n" "$mydate" "$myproj" >> ~/.tasklog
Here is how I would like the output to look.
* By logging in to this machine, you agree to adhere to...............
Last login: Sun Apr 03 17:19:00 2011 from dsl-xx-xxx-xxx-xx.dsl.pltnxx.sbcglobal.net
--- tasklog ---
Hi, Name Here....
The most recent task log entries are:
Sun Apr 03 17:16:02 PDT 2011: Testing my solution for blah blah
Sun Apr 03 17:16:49 PDT 2011: Having some entries so I can demonstrate how this should look...
Sun Apr 03 17:19:26 PDT 2011: Finishing the writeup for blah blah
*** What do you plan to work on during this session? ***
Not a whole lot, to be honest.
Thanks!
ts....@csc:~$
After this, file ~/.tasklog should have contents like:
Sun Apr 03 17:16:02 PDT 2011: Finishing the writeup for blah blah
Sun Apr 03 17:18:49 PDT 2011: Testing my solution
Sun Apr 03 17:19:26 PDT 2011: Having some entries so I can demonstrate how this should look...
Sun Apr 03 17:20:18 PDT 2011: Not a whole lot, to be honest.
---------- Post updated at 02:49 PM ---------- Previous update was at 12:11 PM ----------
So I am very close now to what I want to achieve.
I could use a little help though yet with my date format.
What I would like to see is this for each listed task:
Sun Apr 03 17:16:49 PDT 2011: Having some entries so I can demonstrate how this should look...
So I need to adjust something so that format doesnt show in there and would also like it to diplsay the day and times as shown in sample above.
Here is my entire current output upon script running at login,
Last login: Sun Apr 24 14:17:00 2011 from X7.xxx.25x.xxx
Hi, Joe Shmoe
04/24/11 11:57:22:
mydate=`date +"%D %T"`
04/24/11 14:11:45: Oh not a lot, just making sure I finally got this done right.
04/24/11 14:22:34: Just making up some small scripts
**** What do you plan to work on during this session? ****
Also just realized, I still haven't figured how to get it to say "Thanks" after I enter my task for todays session, and then drop me to command line.
As it is now, I answer and it then drops me to command line.
I know I need to echo "Thanks" in there, but not sure what or where to place it and if it needs something after.
---------- Post updated at 04:00 PM ---------- Previous update was at 02:49 PM ----------
Ok, I finally got it.
Thanks to anyone who even read this.
Working as intended:
#!/bin/bash
echo "---TaskLog---"
n=1
while read curline; do
lasttasks[$n]=${curline}
((n++))
done < ~/.tasklog
if [ $n -le "6" ]; then
n=6
fi
echo "Hi, Joe Shmoe"
for ((i=n-5;i<n;i++))
do
printf "%s\n" "${lasttasks}"
done
echo "**** What do you plan to work on during this session? ****"
read myproj
mydate=`date`
printf "%s: %s\n" "$mydate" "$myproj" >> ~/.tasklog
echo "Thanks"