Help making a tasklog script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help making a tasklog script
# 1  
Old 04-23-2011
Making a tasklog script {SOLVED}

I am trying to create a program called tasklog that integrates with one of my online accounts, to keep track of what tasks I have been working on.
On login, I'd like it to display (up to) the five most recent entries, then ask me what I plan to work on during the new session. I then will type an answer, which will be stored in the log.

Example:
When I log in, I would like to be presented with the following:

--- tasklog ---
Hi,(name here).
The most recent task log entries are: (Up to five log entries printed here, in descending order of date.)
*** What do you plan to work on during this session? ***
At this point, I would like to enter a one-line description of what I will be working on, e.g.
Trying to get this task done, already!
After typing in my entry, it should be logged to the log file with date included, as in the examples below.
Then my script will just say:
Thanks!
, and I will be dropped at the command line.





Couple of specifics:
  • Write the script in file ~/bin/tasklog
  • Modify startup scripts so that tasklog will run immediately before I am presented with a command line.
  • The script needs to store log entries in file ~/.tasklog


If anyone could help me to make such a script that allows for this type of logging, I would be most grateful. Thanks to any and all who read this.

Last edited by santod; 04-24-2011 at 11:39 PM..
# 2  
Old 04-23-2011
Hi.

We will always ask you to show what you have done so far ... cheers, drl
This User Gave Thanks to drl For This Post:
# 3  
Old 04-23-2011
Quote:
Originally Posted by drl
Hi.

We will always ask you to show what you have done so far ... cheers, drl
Yes, I completely understand that perspective.
I am unfortunately currently stuck away from my main PC and am relying on mobile browsing to get this post out there, in hopes to have gotten some type of help on this by the time I return to my home computer. Which is where all of my failed attempts also reside. Smilie
I appreciate your time for at least reading and attempting to help and reply.
Thank you for that. Though I am hopeful that this may be easy enough for someone more knowledgeable then me, to help me soon, I will definitely try and post up what I have tried so far as soon as physically possible.
Thanks again to all who read this and especially anyone who can lend a hand.
# 4  
Old 04-24-2011
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.

Code:
#!/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[i]}"
    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.
Code:
* 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,
Code:
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. Smilie
Thanks to anyone who even read this.


Working as intended:

Code:
#!/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[i]}"
    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"


Last edited by santod; 04-24-2011 at 07:14 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help me making this script

This script is executed whenever a new vehicle is added to the cycle-motor park of campus. The script asks for the following information about the car and adds a new line to the vehicle file.txt: name (name of an animal, unique identifier), color, mark, model, type (e.g., electrical, manual),... (2 Replies)
Discussion started by: andre2222
2 Replies

2. AIX

Making a trace for a script

Hello experts, I'm trying to make a trace (unix log) in hope to see why I have differences in some bases : I putted at the first { and in the last line } > $DATA_SAS 2>&1 Is it a right command ? Do you have another solution ? thank you, regards, (7 Replies)
Discussion started by: rimob
7 Replies

3. Shell Programming and Scripting

Making any script executable

Hi all, I'm new to Unix so just wanted some help. I've been self learning and came accross a question online that I was trying. It is to make any shell script executable, the name of the file is to be made executable. I would use nano and type in something like #! /bin/bash Chmod +x... (4 Replies)
Discussion started by: HelenaR
4 Replies

4. Shell Programming and Scripting

Need Help With making this script

Hello, im a new user on this site and learning scripting very slowly at a understanding pace. However i am up with a challenge and require help completing this. The script has to include arguments, variables, decisions and loops. So the script is about calculating the broadcast address for any... (5 Replies)
Discussion started by: tHe666
5 Replies

5. Shell Programming and Scripting

I could use some help with making a script

I run a small instrument lab. We track our user's time on the instruments with a very manual process of 'last wtmp.1' then cut/paste data into spreadsheets. My boss makes the initial spreadsheets then I convert and format them for uploading into our billing software (COReS). Cores is looking for a... (8 Replies)
Discussion started by: jpontius
8 Replies

6. Shell Programming and Scripting

making shell script

Hi , I am new to shell scripting I want to make script as to execute followng command mysqldump -u (user name) -p(password) database name>filename.sql this file saves with current date and time and execute automatically at particular time which I give (10 Replies)
Discussion started by: kaushik02018
10 Replies

7. Shell Programming and Scripting

making script

hello experts cany any one help me i want to make one script which can rlogin to another machine . but it should not ask me username/password from me of another machine it should take the username and password from the script only. please help me out. regards, shary (2 Replies)
Discussion started by: shary
2 Replies

8. Shell Programming and Scripting

Need help making a script

Here is what I have: #!/bin/bash # Setup year date and month YR=`date +%Y '{print $6}'` MON=`date +%b '{print $2}'` DAY=`date +%d '{print $3}'` file=$YR$MOY$DOM # clear # Dump database using USER/PASS to ..sql mysqldump --user=me -ppass database > database-db.$file.sql The YR, MON and... (2 Replies)
Discussion started by: npereira
2 Replies

9. Shell Programming and Scripting

Making flags for my script

I have no idea how to make my own flags. (6 Replies)
Discussion started by: rcunn87
6 Replies

10. Shell Programming and Scripting

Making a script exectuable

Hi, I'm pretty new to Unix and I just have a question concerning making a script executable without putting the "sh" command before it. In case it makes the difference I am on an Apple computer using the Terminal. Anyway here is the little test code I wrote followed by the commands I took to try to... (5 Replies)
Discussion started by: BuyoCat
5 Replies
Login or Register to Ask a Question