How to time stamp executed commands?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to time stamp executed commands?
# 1  
Old 10-21-2013
How to time stamp executed commands?

Hi guys,
I am executing a pretty long ksh script and need to time stamp every command which runs inside.
Unfortunatly 'echo date' is not the option here.
May be someone knows another way or utility which can be used to log executed command and timestamp next to it.
Thanks
PS I work in ksh88
# 2  
Old 10-21-2013
What are you trying to accomplish - displaying time is not anything like a usual requirement. Besides you will need a really fine grained timer to do this. Many commands in ksh shell are builtins and run with very little elapsed time.

In other words what is the purpose of timing each command? Performance analysis? See if
Code:
set -x

- as the first line of code, doesn't help you.
# 3  
Old 10-21-2013
You can enable the command accounting tool. Not sure what OS you're using, but the package is usually named psacct.

Once enabled, you can display information for any running script and/or prog and all the commands associated with it:

Code:
cat myscript.sh
#!/bin/bash
date
uptime

./myscript.sh
Mon Oct 21 09:14:54 EDT 2013
 09:14:54 up 2 days, 21:52,  8 users,  load average: 0.04, 0.17, 0.13

lastcomm --user <username that ran the script> | more
myscript.sh          username pts/1      0.00 secs Mon Oct 21 09:14
uptime                username pts/1      0.00 secs Mon Oct 21 09:14
date                   username pts/1      0.00 secs Mon Oct 21 09:14

To enable it if not already installed, install the psacct package. Once installed follow the below steps using sudo or as root:

Code:
1.  Create the empty accouting file:

    touch /var/log/pacct

2.  Run the accton command to turn on accounting:

    accton on
    Turning on process accounting, file set to the default '/var/log/pacct'.

3.  Use the lastcomm command to view recently run commands:

    By user:
    lastcomm --user <username>

    By command:
    lastcomm --command <command>

    List everything:
    lastcomm

# 4  
Old 10-21-2013
Not sure if this will work in ksh88. I tried it in recent bash:
Code:
export PS4=" \t "
set -x
./test
  21:53:55 (( i=1 ))
  21:53:55 (( i<=10 ))
  21:53:55 sleep 1
  21:53:56 echo X
X
  21:53:56 (( i++ ))
  21:53:56 (( i<=10 ))
  21:53:56 sleep 1
  21:53:57 echo X

etc.
# 5  
Old 10-29-2013
Thanks a lot, guys...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

System time and Cron time stamp not matching

On Solaris 10 server the system date won't match with the timestamp on files created by a cron jobs, Please help here is what i get when i check for system date infodba-ie10ux014:/tcpdv1_ie10/tcadmin/bin\n\r-> date Tue Apr 24 15:27:43 GMT 2012at same time i executed a cron job, and checked... (4 Replies)
Discussion started by: karghum
4 Replies

2. UNIX for Dummies Questions & Answers

Clearing history of commands executed

Hi, I have cleared the commands by using >$HOME/.sh_history. But if i issue HISTORY it shows some reference numbers but not the commands executed. But i want to truncate those line numbers too. May i know how i can achieve this? Thanks (1 Reply)
Discussion started by: pandeesh
1 Replies

3. Shell Programming and Scripting

How to get time duration between two human readable time stamp in Unix?

Here is two time I have: Jul 12 16:02:01 Jul 13 01:02:01 and how can I do a simple match to get difference between two time which is 09:00:00 Thanks in advance. (3 Replies)
Discussion started by: ford99
3 Replies

4. Shell Programming and Scripting

How to list Commands used by users & with time stamp

hi, Do anybody know, how to list out all the commands & scripts used by the user & root along with the timestamps under ksh & csh shells. Thanks in advance Regards BS (1 Reply)
Discussion started by: raghunsi
1 Replies

5. Shell Programming and Scripting

To inform the executed commands

Dear friends, Whenever I do logout from a session initiated by ssh/su, I need to print a small report which says the login time, logout time, commands got executed.. How can it be done? I know when doing ssh, .profile file will get executed. Shall we do something with the help of it. (1 Reply)
Discussion started by: nagalenoj
1 Replies

6. UNIX for Dummies Questions & Answers

multiple commands to be executed at the same time

how to execute more than one command at the same time in unix .. (4 Replies)
Discussion started by: hemaa
4 Replies

7. Shell Programming and Scripting

Viewing the commands executed

Hi, I have executed a set of commands on the linux server and later rebooted the server. Is it possible to get the details of the commands I executed prior to the reboot? If yes please let me know how? Thanks. (1 Reply)
Discussion started by: yoursdavinder
1 Replies

8. Solaris

Can history commands show what time command executed

On Solaris 8 and 10 is there a way history command can show what time a particular command was executed. Pls reply. Thanks (2 Replies)
Discussion started by: Tirmazi
2 Replies

9. UNIX for Dummies Questions & Answers

How does the internal commands are executed?

Hi all, I am new to unix OS. Commands(external commands) given by the user are examined by shell and later executed by kernel. Now I want to know how the internal(built in) commands are executed. Please clarify whether they are executed directly by shell or by kernel. Thanks in... (2 Replies)
Discussion started by: chaitra
2 Replies

10. Solaris

I want to know whole day commands executed by particular user

Hi all I want to know the commands executed a by particular user .. for the whole day on my machine. I have checked out with the commad $lastcomm <user> It is throwing an error called: .. /var/adm/pacct: No such file or directory Can u help me in this regard.. Thank U... (3 Replies)
Discussion started by: naree
3 Replies
Login or Register to Ask a Question