Skip to content

Instantly share code, notes, and snippets.

@seunggabi
Created March 2, 2020 16:29
Show Gist options
  • Save seunggabi/22ebcabef7133177f071cadeb556149b to your computer and use it in GitHub Desktop.
Save seunggabi/22ebcabef7133177f071cadeb556149b to your computer and use it in GitHub Desktop.
print_access_log.sh
#!/bin/sh
# ./print_access_log.sh keyword 20200302 server_list.txt
### server_list.txt ###
a
b
c
#######################
keyword=$1
file=/home1/irteam/logs/apache/access.log.$2
servers=()
IFS=$'\n'
for line in `cat $3`; do
servers+=("$line")
done
for i in "${servers[@]}"
do
logs=$(/usr/local/bin/rsh -l irteam ${i} grep -r ${keyword} ${file})
IFS='' read -r line <<< $logs
if [ line ]
then
echo "["$i"] "$line
else
echo "["$i"] empty"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment