SmartOS chyba při spouštění /smartdc/bin/sdc-lastcomm cronem

Pokud už vás nebaví po přihlášení do SmartOS global zóny hláška You have new mail a vidíte ve /var/mail/root chybu:

find: stat() error ./20150420000000.not_terminated.host: No such file or directory

má to snadnou nápravu. Bude ale potřeba upravit soubor /smartdc/bin/sdc-lastcomm. Abych si to zjednodušil, vytvořil jsem patch:

--- /smartdc/bin/sdc-lastcomm	Fri May 30 03:16:17 2014
+++ /smartdc/bin/sdc-lastcomm	Tue Apr 21 11:23:16 2015
@@ -48,10 +48,19 @@
 		echo "-R is not valid with -d"
 		exit 1
 	fi
+	MAX_SLEEP=3
+	cd "$DIR" || exit 1
+	# Save the current audit log filename
+	AUDIT_LOG=`find . -name "*.not_terminated.*"`
 	# Rotate and trim the audit logs
 	audit -n
-	cd "$DIR" || exit 1
-	find . -type f -mtime +$DAYS -print0 2>/dev/null | xargs -0 rm -f
+	# Wait until old log is closed or MAX_SLEEP seconds
+	while [[ -f $AUDIT_LOG && $MAX_SLEEP ]]; do
+		MAX_SLEEP=$((MAX_SLEEP - 1))
+		sleep 1
+	done
+	# Find and delete $DAYS old files
+	find . -type f -mtime +$DAYS -print0 2>/dev/null | xargs -0 rm -f
 	exit 0
 fi
 

Patch nejlépe provede takto:

$ curl --insecure -s https://gist.githubusercontent.com/foxycode/f12e9bc4f7af24436e90/raw/22ff6087002c45893e35dea09aa55809ce2069aa/sdc-lastcomm.patch | patch /smartdc/bin/sdc-lastcomm

Více info v Github repozitáři SmartOS

Update: 15.10.2015 upraveno pro verzi 20151015T063628Z

Napsat komentář

Vaše e-mailová adresa nebude zveřejněna.