cron_history.sh 418 Bytes
Newer Older
Afaq Tariq's avatar
Afaq Tariq committed
1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash

grepCmd=$(which grep)
cronLog='/var/log/syslog'
numberOfLines='50'

# Month, Day, Time, Hostname, tag, user,

result=$($grepCmd -m$numberOfLines CRON $cronLog \
	| awk '{ s = ""; for (i = 6; i <= NF; i++) s = s $i " "; \
			print "{\"time\" : \"" $1" "$2" "$3 "\"," \
					"\"user\" : \"" $6 "\"," \
13
					"\"message\" : \"" $5" "gensub("\"", "\\\\\"", "g", s) "\"" \
Afaq Tariq's avatar
Afaq Tariq committed
14
15
16
17
				"},"
			}'
	)

18
echo [${result%?}]