X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=blobdiff_plain;f=shell%2Fsudo-logs.sh;fp=shell%2Fsudo-logs.sh;h=d925434f8566bf1fe9754e4590fa54a5b9463f12;hb=ca1763c074a62c626b76e21886347dcffbf15dcd;hp=0000000000000000000000000000000000000000;hpb=200c13dbad2552db1ba9cfc185b0dc40db863930;p=releng%2Fglobal-jjb.git diff --git a/shell/sudo-logs.sh b/shell/sudo-logs.sh new file mode 100755 index 00000000..d925434f --- /dev/null +++ b/shell/sudo-logs.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# SPDX-License-Identifier: EPL-1.0 +############################################################################## +# Copyright (c) 2019 The Linux Foundation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +############################################################################## +echo "---> sudo-logs.sh" + +set -eu -o pipefail -o noglob + +# Copy/Generate 'sudo' log and copy to archive directory +function copy_log() +{ + case $os in + fedora|centos|redhat|ubuntu|debian) + if ! sudo cp $sudo_log /tmp; then + echo "Unable to archive 'sudo' logs ($sudo_log)" + return + fi + ;; + suse) + # Do I need 'sudo' to run 'journalctl'? + journalctl | grep sudo > $sudo_log + ;; + *) echo "Unexpected 'operatingsystem': $os" + exit 1 + ;; + esac + sudo_log=$(basename $sudo_log) + sudo chown jenkins:jenkins /tmp/$sudo_log + chmod 0644 /tmp/$sudo_log + mkdir -p $WORKSPACE/archives/sudo + mv /tmp/$sudo_log $WORKSPACE/archives/sudo/$sudo_log + +} # End copy_log() + +echo "Archiving 'sudo' log.." +os=$(facter operatingsystem | tr '[:upper:]' '[:lower:]') +case $os in + fedora|centos|redhat) sudo_log=/var/log/secure ;; + ubuntu|debian) sudo_log=/var/log/auth.log ;; + suse) sudo_log=/tmp/sudo.log ;; + *) echo "Unexpected 'operatingsystem': $os" + exit 1 + ;; +esac + +copy_log