Verified Commit 8e84457f authored by Xueshan Feng's avatar Xueshan Feng
Browse files

added --timestamp.

parent 7e35b1c5
Loading
Loading
Loading
Loading
+25 −6
Original line number Diff line number Diff line
@@ -3,10 +3,23 @@
# sfeng@stanford.edu 2018
# 
# Read AWS cloudwatch logs. Default is logs from 5 minutes ago.
# See https://github.com/jorgebastida/awslogs for full usage information.

usage_example(){
  echo
  echo "Usage examples:"
  echo "$program groups: get all log groups"
  echo "$program get <group name>: get logs for the named log group"
  echo "$program streams <group name>: get all stream names for the given group"
  echo "$program get <group name> <stream name>: get all events  for a group with a stream name."
  echo
  echo "get command has default 5 minutes start time. you can use --since=1{d,m,w} for starting time."
  echo "get command can also use 'ALL --watch' option to tail a log."
  echo "See https://github.com/jorgebastida/awslogs for full usage information."
  exit 0
}

### MAIN
program=$(basename $0 .sh | sed 's/-/_/g')
program=$(basename $0 | sed 's/-/_/g')

cmd=${@:-'--help'}

@@ -21,9 +34,15 @@ if [ "$aws_profile" = "NODEFAULT" ]; then
  exit 1
fi

echo Running $program...
if docker run --rm -it -v $HOME/.aws:/root/.aws suet/awslogs $cmd --profile=$aws_profile | grep "An error occurred"; then
  docker run --rm -it -v $HOME/.aws:/root/.aws suet/awslogs --help
echo Running $program $cmd --profile=$aws_profile...
if [ "$cmd" = "--help" ] ;then
  docker run --rm -it suet/awslogs $cmd
  usage_example
fi
if docker run --rm -it -v $HOME/.aws:/root/.aws suet/awslogs $* --profile=$aws_profile | grep "An error occurred"; then
  usage_example
else
  docker run --rm -it -v $HOME/.aws:/root/.aws suet/awslogs $cmd --profile=$aws_profile
  docker run --rm -it -v $HOME/.aws:/root/.aws suet/awslogs $* --profile=$aws_profile --timestamp > /tmp/output.$$
fi
cat /tmp/output.$$
echo "File is saved at /tmp/output.$$."