I need to record the real user and the real time into the history list. For that I use trap 'who am i|read -s' debug
, but it does not record the real time. Here are the steps so you can verify this.
sudo su - wsadmin
Run who am i
, it returns:
byksk0 pts/0 2015-10-08 10:38 (255.255.255.0)
Rerun who am i
, it ALWAYS returns:
byksk0 pts/0 2015-10-08 10:38 (255.255.255.0)
regardless how long this is run after the sudo su -
command.
Is it possible to get the real time when a command is executed under wsadmin?
The "who" command returns the login time, not the time of execution of a last command or anything like it. To get a timestamp: use the "date" command.
EDIT:
If you want that on one line:
who am i | awk '{printf "%s ", $1}' && date
EDIT:
To try to anticipate the next question: Date also supports formatting of the date and time it outputs e.g:
$ who am i | awk '{printf "%s ", $1}' && date "+%Y-%m-%d %H:%M:%S"
swa66 2015-10-08 21:20:34