Tag Info

Hot answers tagged

14

I suggest to take a look at bash variable SECONDS: SECONDS: Each time this parameter is referenced, the number of seconds since shell invocation is returned. If a value is assigned to SECONDS, the value returned upon subsequent references is the number of seconds since the assignment plus the value assigned. Thus you can simply ...


8

Prefix your command with /usr/bin/time and the time command will output the time it took the script to run. This is more portable than the using something bash specific.


5

While using SECONDS and time will give you relative values. If you'd like to have absolute values for Auditing and Reporting Purposes as to when the script ran and when it completed, you might want to try something like this before and after your commands date '+%Y%m%d%H%M%S.%N' . This could also give you a better granularity as it can capture ...


4

This is kind of hacky and unscriptable, but might get you what you're looking for. Firefox can run javascript via command line like so: firefox "javascript:alert(Date.now())" That will open Firefox and run javascript to pop up a message box containing the number of milliseconds in epoch time. You can get the number of milliseconds elapsed in epoch time ...


2

The simplest way is to use the --printf option as suggested by @don_crissti: stat --printf='%A %h %U %G %s %.16y %n\n' .bashrc If, for whatever reason, you can't do that you can parse the output of `stat -c '%y': $ stat -c'%A %h %U %G %s %y %n' .bashrc | awk '{$7=substr($7,1,8); $8=""}1;' -rw-r--r-- 1 terdon terdon 9737 2015-02-01 18:12:18 .bashrc Or ...


2

start a listening netcat in the background call firefox to connect it wait it with a wait bash builtin. finally kill everything nc -l 64738 & firefox http://127.0.0.1:64738 & wait <...yet to be solved that only the nc should be waited for...> killall firefox <..yet to be solved to not kill your girlfriends browser>


1

#!/bin/sh EPOCH='jan 1 1970' sum=0 for i in 00:03:34 00:00:35 00:12:34 do sum="$(date -u -d "$EPOCH $i" +%s) + $sum" done echo $sum|bc date -u -d "jan 1 1970" +%s gives 0. So date -u -d "jan 1 1970 00:03:34" +%s gives 214 secs.


1

If you cannot (or don't want) use TIMEFORMAT your just need to transfer time into seconds, then add it together. For example pipe output through: { sum=0 while IFS="[ :]" proc_name h m s do let sum+=$((60*($m+60*$h)+$s)) done echo $sum } Or if you'd like can exchange last echo-command by printf ...


1

You can use some tool which can get window id associated with PID, and wait until that window is created. The process id of previously started program is available in $! variable. As an example - using wmctrl one can get list of all windows and check if any of them is started by given PID: $ wmctrl -lp 0x00e00003 -1 397 jjmach sawfishpager 0x01200003 6 ...



Only top voted, non community-wiki answers of a minimum length are eligible