| 1 | #!/bin/bash |
| 2 | |
| 3 | # This file is part of util-linux. |
| 4 | # |
| 5 | # This file is free software; you can redistribute it and/or modify |
| 6 | # it under the terms of the GNU General Public License as published by |
| 7 | # the Free Software Foundation; either version 2 of the License, or |
| 8 | # (at your option) any later version. |
| 9 | # |
| 10 | # This file is distributed in the hope that it will be useful, |
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | # GNU General Public License for more details. |
| 14 | |
| 15 | TS_TOPDIR="${0%/*}/../.." |
| 16 | TS_DESC="last" |
| 17 | |
| 18 | . "$TS_TOPDIR"/functions.sh |
| 19 | ts_init "$*" |
| 20 | |
| 21 | ts_check_test_command "$TS_CMD_LAST" |
| 22 | ts_check_test_command "$TS_CMD_UTMPDUMP" |
| 23 | ts_check_prog "ln" |
| 24 | |
| 25 | $TS_CMD_LAST --version 2>&1 | grep -q "invalid option" \ |
| 26 | && ts_skip "deprecated last" |
| 27 | |
| 28 | . "$TS_SELF/utmp_functions.sh" |
| 29 | |
| 30 | WTMP_FILE=${TS_OUTDIR}/wtmp-a |
| 31 | rm -f $WTMP_FILE |
| 32 | |
| 33 | export LANG=C |
| 34 | export TZ=GMT |
| 35 | |
| 36 | if [ $SIZEOF_UTMP -eq 384 ]; then |
| 37 | ln -s ${TS_SELF}/wtmp-a.${BYTE_ORDER} $WTMP_FILE |
| 38 | else |
| 39 | $TS_CMD_UTMPDUMP -r ${TS_SELF}/txt-a > $WTMP_FILE 2>/dev/null \ |
| 40 | || ts_skip "can't create test data" |
| 41 | fi |
| 42 | |
| 43 | # there is no better way yet to skip a subtest |
| 44 | if ts_resolve_host "a.root-servers.net" >/dev/null; then |
| 45 | ts_init_subtest "dns" |
| 46 | |
| 47 | ts_log "~~~ dns short ~~~" |
| 48 | $TS_CMD_LAST -f $WTMP_FILE -d root >> $TS_OUTPUT 2>/dev/null |
| 49 | |
| 50 | ts_log "~~~ dns long ~~~" |
| 51 | $TS_CMD_LAST -f $WTMP_FILE -w -d root >> $TS_OUTPUT 2>/dev/null |
| 52 | |
| 53 | ts_log "~~~ dns host last ~~~" |
| 54 | $TS_CMD_LAST -f $WTMP_FILE -a -d root >> $TS_OUTPUT 2>/dev/null |
| 55 | |
| 56 | ts_finalize_subtest |
| 57 | fi |
| 58 | |
| 59 | ts_init_subtest "nodns" |
| 60 | ts_log "~~~ basic output ~~~" |
| 61 | $TS_CMD_LAST -f $WTMP_FILE >> $TS_OUTPUT 2>/dev/null |
| 62 | |
| 63 | ts_log "~~~ include system ~~~" |
| 64 | $TS_CMD_LAST -f $WTMP_FILE -x >> $TS_OUTPUT 2>/dev/null |
| 65 | |
| 66 | ts_log "~~~ show ip ~~~" |
| 67 | $TS_CMD_LAST -f $WTMP_FILE -i torvalds >> $TS_OUTPUT 2>/dev/null |
| 68 | |
| 69 | ts_log "~~~ no host ~~~" |
| 70 | $TS_CMD_LAST -f $WTMP_FILE -R torvalds >> $TS_OUTPUT 2>/dev/null |
| 71 | |
| 72 | ts_log "~~~ full times shortopt ~~~" |
| 73 | $TS_CMD_LAST -f $WTMP_FILE -F >> $TS_OUTPUT 2>/dev/null |
| 74 | |
| 75 | ts_log "~~~ full times longopt ~~~" |
| 76 | $TS_CMD_LAST -f $WTMP_FILE --time-format=full >> $TS_OUTPUT 2>/dev/null |
| 77 | |
| 78 | ts_log "~~~ no time ~~~" |
| 79 | $TS_CMD_LAST -f $WTMP_FILE --time-format=notime >> $TS_OUTPUT 2>/dev/null |
| 80 | |
| 81 | ts_log "~~~ iso-8601 time ~~~" |
| 82 | $TS_CMD_LAST -f $WTMP_FILE --time-format=iso -w >> $TS_OUTPUT 2>/dev/null |
| 83 | |
| 84 | ts_log "~~~ since and until ~~~" |
| 85 | $TS_CMD_LAST -f $WTMP_FILE -s "2013-08-28 02:20" -t "2013-08-28 08:20" >> $TS_OUTPUT 2>/dev/null |
| 86 | |
| 87 | ts_log "~~~ present ~~~" |
| 88 | $TS_CMD_LAST -f $WTMP_FILE -p "2013-08-28 11:20" >> $TS_OUTPUT 2>/dev/null |
| 89 | ts_finalize_subtest |
| 90 | |
| 91 | rm -f $WTMP_FILE |
| 92 | |
| 93 | ts_finalize |