Need to generate a record that yields start time & end time

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
gcmartin

Need to generate a record that yields start time & end time

#1 Post by gcmartin »

I am new to CLI Linux appl.

I want to be able to record the start time of a script start and its end time on a single record.

Can anyone suggest something?

Thanks in advance

DPUP5520
Posts: 800
Joined: Wed 16 Feb 2011, 05:38

#2 Post by DPUP5520 »

uh you mean like a stopwatch? pclock has one of those.
[url=http://www.murga-linux.com/puppy/viewtopic.php?t=69651][b][i]PupRescue 2.5[/i][/b][/url]
[url=http://www.murga-linux.com/puppy/viewtopic.php?t=72178][b][i]Puppy Crypt 528[/i][/b][/url]

gcmartin

#3 Post by gcmartin »

DPUP5520 wrote:uh you mean like a stopwatch? pclock has one of those.
Thanks DPUP5520. I need to record a start time, issue a command line (CL) command then capture the end time. It would be nice to see elapse time in the same record. This doesn't have to be fancy or in a GUI. Essentially, it would produce a record of start, I would execute my CL command (say cp "file1 file2") and record and post the completion time on exit. Kinda like this:

Code: Select all

# record_time_script
....something capture start time
cp file1 file2
....something reports start-time and current time (and maybe elasped time)
exit
Thanks for guidance.

stu90

#4 Post by stu90 »

im sure some one with more knowledge will chime in but in the mean time what about some thing like:

Code: Select all

#!/bin/sh
time_start=`date +%R:%S`

mtpaint &

time_end=`date +%R:%S`

echo -e ":Started: \e[1;31m$time_start\e[0m :Ended: \e[1;31m$time_end\e[0m" 
echo start / end time when script is run from terminal.

or to see how long a script takes to run use command in terminal:

time myscript

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#5 Post by vovchik »

Dear Stu and dcmartin,

What about something like this:

Code: Select all

#!/bin/sh
# provide app name on command line
myprog="$@"
mydate=`date +%y-%m-%d`
before=`date +%s`
time_start=`date +%R:%S` 
# application launch
"$myprog"
after=`date +%s`
time_end=`date +%R:%S` 
elapsed_seconds=`expr $after - $before`
# results
echo "Date         : $mydate"
echo "Application  : $myprog"
echo "Start time   : $time_start"
echo "End time     : $time_end"
echo "Elapsed time : $elapsed_seconds seconds"
The results could be piped to a file, and this little routine could also be guified.

With kind regards,
vovchik

User avatar
tasmod
Posts: 1460
Joined: Thu 04 Dec 2008, 13:53
Location: North Lincolnshire. UK
Contact:

#6 Post by tasmod »

gcmartin,

If I'm not mistaken this is for your ip status.

Beware running the script too often to check your IP. What you are doing is making a call to someones website, this then runs its script and returns your IP.
However, they won't be too happy if you poll it often, you will be using their bandwidth. Best you could achieve is an approximation.

A better solution may be to see if your router can log event changes. Mine can I'm sure. The log can be parsed for the info you require.
Rob
-
The moment after you press "Post" is the moment you actually see the typso 8)

stu90

#7 Post by stu90 »

vovchik wrote:Dear Stu and dcmartin,

What about something like this:

The results could be piped to a file, and this little routine could also be guified.

With kind regards,
vovchik
Hi vovchik,
i have added a yad GUI and a some colour to the terminal output on your script :)

Image

Code: Select all

#!/bin/sh 
 # provide app name on command line 
 red="\e[1;31m"
 co="\e[0m"
 myprog="$@" 
 mydate=`date +%y-%m-%d` 
 before=`date +%s` 
 time_start=`date +%R:%S` 
 # application launch 
 "$myprog" 
 after=`date +%s` 
 time_end=`date +%R:%S` 
 elapsed_seconds=`expr $after - $before` 
 # results 
 echo -e "Date         : "$red"$mydate"$co"" 
 echo -e "Application  : "$red"$myprog"$co"" 
 echo -e "Start time   : "$red"$time_start"$co"" 
 echo -e "End time     : "$red"$time_end"$co"" 
 echo -e "Elapsed time : "$red"$elapsed_seconds seconds"$co""
 
 yad --title="Time Results" --text="
 Date         : <b>$mydate</b> \n
 Application  : <b>$myprog</b> \n
 Start time   : <b>$time_start</b> \n
 End time     : <b>$time_end</b> \n
 Elapsed time : <b>$elapsed_seconds seconds</b> "

thanks.

gcmartin

#8 Post by gcmartin »

tasmod wrote:gcmartin, If I'm not mistaken this is for your ip status.
...
Thanks @Tasmod, but that is not the mission of the request for help.

I am looking to get a tool/method of measuring behavior. This contributions are of "Extreme Value", to me, as its use intends to remove some subjectivity from much of what I'm reporting to this community.

This community is maturing very fast. It also expanding exponentially; obvious over the achievements of the last year. Much of what the community has done has been on emotional guidance. I now see more and more movement to expand emotional into the realm of "objective emotion" as it continues to grow and expand. This expansion is generating a "Public Open Source Software Product", beyond the likes of anything the planet has seen (although, its not defining itself as that yet).

But, you are right about your observation of postings I've made about the network tools that DPUP5520 has made available to the community. Those are positive contributions, but his work is designed to help us on the LAN level versus WAN. I currently have not seen any work, by him, at the WAN level which you refer. Appears that his tools are for local LAN administration use/needs.

So, I looking at some ways to improve what we report, usefully. And, I want to investigate some simple ways of doing this that is easily understood when seen within the community.

Thanks @STU90 and @Vovchik. The 2 of you have "hit the nail on the head". What a creative effort in the blink of an eye! One of you should make this a pet. I see it sitting along side Hardinfo on the Menu. This is very thoughtful, does not use CPU while command is running, and reports/records as needed for evaluation. Really, really outstanding effort!

This may become wide-spread in use and reporting either as a base for reporting or simply as eye-check reference.

What should it be named?

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

app timer

#9 Post by vovchik »

Dear stu and dcmartin,

@stu: great.

@both: I also think that an echo >> /root/.appstats/appstats.log might be a nice enhancement, using either "|" or "," as a delimiter to a single-line multi-field record, which would contain the app name (basename $myprog, start time, end time and elapsed time). And the gui could have "Log" and "View" buttons (sorting either by date or by app name). Just an idea. I have no idea what this little utility should be called. What about "plogger"?

With kind regards,
vovchik

gcmartin

Re: app timer

#10 Post by gcmartin »

vovchik wrote:Dear stu and dcmartin,

@stu: great.

@both: I also think that an echo >> /root/.appstats/appstats.log might be a nice enhancement, using either "|" or "," as a delimiter to a single-line multi-field record, which would contain the app name (basename $myprog, start time, end time and elapsed time). And the gui could have "Log" and "View" buttons (sorting either by date or by app name). Just an idea. I have no idea what this little utility should be called. What about "plogger"?

With kind regards,
vovchik
Thanks. @Vovchik. I like the idea. Though, the log doesn't have to be hidden. Maybe placed in

I initially called it "measureit". Your script works for "measureit hardinfo". BUT does not work for either of the following.
sh-4.1# measure-it hardinfo
Date : 11-06-20
Application : hardinfo
Start time : 10:49:50
End time : 10:50:01
Elapsed time : 11 seconds
sh-4.1# measure-it hardinfo -r
/root/my-applications/bin/measure-it: line 8: hardinfo -r: command not found
Date : 11-06-20
Application : hardinfo -r
Start time : 10:50:19
End time : 10:50:19
Elapsed time : 0 seconds
sh-4.1# measure-it "hardinfo -r"
/root/my-applications/bin/measure-it: line 8: hardinfo -r: command not found
Date : 11-06-20
Application : hardinfo -r
Start time : 10:54:46
End time : 10:54:46
Elapsed time : 0 seconds
sh-4.1#
Thanks in advance for guidance.

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#11 Post by vovchik »

Dear gcmartin,

If you want the parameters passed, just remove the double quotes surrounding "$myprog" as a quick hack. Eventually, we should tally the arguments, run $1 and save that to the log as a separate entry separate from the complete argument list ["$@"]. The argument count is given by "$#". I think this also might be a case for using "getopts".

With kind regards,
vovchik

gcmartin

Works

#12 Post by gcmartin »

vovchik wrote: ... just remove the double quotes surrounding "$myprog" ... Eventually, we should ... .
Thanks @Vovchik

Code: Select all

sh-4.1# measure-it hardinfo -r
Computer
 Summary
 Operating System
 Kernel Modules
 Boots
 Languages
 Filesystems
 Display
 Environment Variables
 Users
Devices
 Processor
 Memory
 PCI Devices
 USB Devices
 Printers
 Battery
sh: -c: option requires an argument
 Sensors
 Input Devices
 Storage
 DMI
 Resources
Benchmarks
 CPU Blowfish
 CPU CryptoHash
 CPU Fibonacci
 CPU N-Queens
 FPU FFT
/root/my-applications/bin/measure-it: line 8: 28451 Segmentation fault      $myprog
Date         : 11-06-20
Application  : hardinfo -r
Start time   : 14:22:38
End time     : 14:23:27
Elapsed time : 49 seconds
sh-4.1# 
You should Publish this creation. Along with your suggestion to expand it. "Measure-it"/"Time-it" or whatever name you find appropriate.

Thanks everyone.

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#13 Post by technosaurus »

I made a function called time2 in bashbox that provides finer grained time difference for running a command than time. It uses only the date applet, and could be adapted to simply log the times rather than output the difference.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
miriam
Posts: 373
Joined: Wed 06 Dec 2006, 23:46
Location: Queensland, Australia
Contact:

#14 Post by miriam »

When I convert videos I have my script save the start time and the end time in a file in the same directory with the video files so that I can go back later and read through the file and see how long a bunch of different conversions took. (I'm always looking for ways to speed up such things.) Here is my vob2avi script that does it:

Code: Select all

if [ $# -eq 0 ]; then
	echo "[34musage: [35mvob2avi <vobfilename>[34m"
	echo "  vob2avi is a wrapper for mencoder used to rip vobs"
	echo "  to avi format."
	echo "  The '.vob' extension can be given or omitted."
	echo "  NOTE: edit this file to tweak various settings:"
	echo "        /root/my-applications/bin/vob2avi[30m"
else
	F_NAME="`basename \"$1\" .vob`"

	echo "$F_NAME" >>done.txt
	date +"%A %Y-%m-%d  %I:%M:%S %P" >>done.txt

	# scale up 720x576->1024x576
	# NOTE: audio ID=128
	# delay audio 0.2sec
	#mencoder "$F_NAME.vob" -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1600:v4mv:mbd=2:trell -aid 128 -nosub -vf scale=1024:576,hqdn3d=2:1:2 -audio-delay -0.2 -oac mp3lame -lameopts vbr=3 -o "$F_NAME.avi"

	systemsound alert

	date +"%A %Y-%m-%d  %I:%M:%S %P" >>done.txt
	echo >>done.txt
fi
Notice that I have this script always writing to the done.txt file with echo and date using the appending redirection symbols >> so that if there is a done.txt file already there in that folder it simply adds the new values to the end of the existing one instead of overwriting it. That way I can accumulate lots of results that I can look over later at my leisure. (I guess I should also point out that if the file doesn't exist yet then the redirection simply creates it.)

I hope this helps.
[color=blue]A life! Cool! Where can I download one of those from?[/color]

Post Reply