Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Get a list of log files from /var/log

  • Loading branch information...
commit 7b66cb75303e682119d36b54f1a741f707194de7 1 parent c3ea774
@Geal authored
Showing with 28 additions and 2 deletions.
  1. +27 −1 logs/logs.sh
  2. +1 −1  logs/logs_show.sh
View
28 logs/logs.sh
@@ -1,3 +1,29 @@
#!/bin/bash
-echo '{ "version": 1, "title": "Commands", "type":"commands", "values" : [ {"name" : "Apache access", "value" : "", "command" : ".pilotssh/logs/logs_show.sh \"Apache access.log\" apache2/access.log" }, {"name" : "Apache error", "value" : "", "command" : ".pilotssh/logs/logs_show.sh \"Apache error.log\" apache2/error.log" }, {"name" : "Auth", "value" : "", "command" : ".pilotssh/logs/logs_show.sh \"Auth.log\" auth.log" }, {"name" : "Syslog", "value" : "", "command" : ".pilotssh/logs/logs_show.sh \"Syslog\" syslog" } ] }';
+if [ "$#" -ne 1 ]
+then
+ path="/var/log"
+else
+ path=$1
+fi
+
+IFS=$'\n'$'\r'
+files=( $(find $path -maxdepth 1 -type f -not -name "*.gz" | sort) )
+dirs=( $(find $path -maxdepth 1 -type d | sort) )
+
+#remove the current directory from the list
+unset dirs[0]
+result='{ "version": 1, "title": "Logs", "type":"commands", "values" : ['
+result=$result"{\"name\":\"$path\", \"value\":\"\", \"command\":\"\"}"
+
+
+for dir in "${dirs[@]}"; do
+ result=$result", {\"name\":\"$dir\", \"value\":\"\", \"command\":\".pilotssh/logs/logs.sh $dir\"}"
+done
+
+for file in "${files[@]}"; do
+ result=$result", {\"name\":\"$file\", \"value\":\"\", \"command\":\".pilotssh/logs/logs_show.sh $file\"}"
+done
+
+result=$result" ]}"
+echo $result
View
2  logs/logs_show.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-ta=`tail -n 100 /var/log/$2`
+ta=`tail -n 100 $1`
t4=`echo "$ta" | base64 -w 0`
echo "{ \"version\": 1, \"title\": \"$1\", \"type\":\"text\", \"status\":\"ok\", \"text\":\"$t4\"}"
Please sign in to comment.
Something went wrong with that request. Please try again.