3 # assorted useful ways of running executables.
5 # Author: Chris Koeritz
9 # similar to timed_grid, but for arbitrary commands, and fits in with the timing
11 function timed_command()
13 echo "[started timer $(readable_date_string)]"
14 $(\which time) -p -o "$TESTKIT_TIMING_FILE" $*
16 echo "[stopped timer $(readable_date_string)]"
22 # uses the timing file to determine how long the last activity took in
23 # seconds and then prints out the value.
26 head -n 1 $TESTKIT_TIMING_FILE | awk '{print $2}'
29 # calculates the bandwidth for a transfer. this takes the elapsed time as
30 # the first parameter and the size transferred as second parameter.
33 local real_time="$1"; shift
34 local size="$1"; shift
35 # drop down to kilobytes rather than bytes.
36 size=$(echo $size / 1024 | $(\which bc) -l)
38 #echo "time=$real_time size=$size"
40 local total_sec="$(echo "$real_time" | awk -Fm '{print $1}'| awk -F. '{print $1}' )"
42 if [[ "$total_sec" =~ .*exited.* ]]; then
43 echo "FAILURE: Test run failed in some way; setting total seconds to very large number."
46 if [ $total_sec -eq 0 ]; then
47 # fake it when we get a math issue where something took less than a second.
50 bandwidth="$(echo "scale=3; $size / $total_sec" | $(\which bc) -l)"
54 # a wrapper for calculateBandwidth that prints out a nicer form of the
55 # bandwidth. it requires the same parameters as calculateBandwidth.
58 echo " Bandwidth $(calculateBandwidth $*) kbps"
63 # connects to a host as a particular user and executes a command there.
64 function run_command_remotely()
67 echo This function connects to a remote host to run a command. It requires
68 echo at least three parameters: the host to connect to, the user name on
69 echo that host which supports passwordless logins, and the command to run.
70 echo The command to run is the third through Nth parameters.
74 # run our expecter to feed commands in, and the last one needs to be exit so we
75 # return to the original host.
76 OUTFILE="$(mktemp $TMP/ssh_run.XXXXXX)"
77 expect $TESTKIT_ROOT/library/ssh_expecter.tcl "$username" "" "$host" "${@}" >"$OUTFILE"
79 # make sure we didn't experience a failure on the other side.
80 grep "YO_FAILURE" $OUTFILE &>/dev/null
82 echo Detected failure running command via ssh.
87 echo ========== output from command ============
89 echo ===========================================
96 #run_command_remotely serene fred "ls /"