<commit_before>#!/bin/sh

# notes
# - doesn't account for Oracle UEK packages
# - removes any kernels that aren't the running or newest-installed version
#
# sample use via root's crontab
# 
# 30 23 * * * yum -q -y update && $HOME/opsscripts/reboot-into-newer-kernel.sh

kernels() {
	rpm -qa --qf '%{INSTALLTIME} %{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' \
		| awk '$2 ~ /^kernel-[0-9]/ { print }'
}

current() {
	echo -n "kernel-$(uname -r)"
}

newest() {
	kernels \
		| sort -n \
		| awk -vur="$(current)"  '{
			if($2 == ur) {
				show=1
			}
			if (show == 1) {
				print $2
			}
		}' \
		| tail -1 \
		| awk '{ print $1 }'
}

current="$(current)"
newest="$(newest)"

if [ "$current" != "$newest" ] ; then
	for kernel in $(kernels | awk '{ print $2 }') ; do
		if test "$current" != "$kernel" && test "$newest" != "$kernel" ; then
			echo "cleaning up old kernel: $kernel"
			yum -q -y remove $kernel
			echo
		fi
	done
	echo "adding at job to reboot into the updated kernel: $newest"
	echo reboot | at now+1 minute
fi
<commit_msg>Amazon Linux AMI "reboot" does not seem to work in at jobs<commit_after>#!/bin/sh

kernels() {
	rpm -qa --qf '%{INSTALLTIME} %{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' \
		| awk '$2 ~ /^kernel-[0-9]/ { print }'
}

current() {
	echo -n "kernel-$(uname -r)"
}

newest() {
	kernels \
		| sort -n \
		| awk -vur="$(current)"  '{
			if($2 == ur) {
				show=1
			}
			if (show == 1) {
				print $2
			}
		}' \
		| tail -1 \
		| awk '{ print $1 }'
}

current="$(current)"
newest="$(newest)"

echo "current kernel: $current"
echo "newest kernel : $newest"

if [ "$current" != "$newest" ] ; then
	for kernel in $(kernels | awk '{ print $2 }') ; do
		if test "$current" != "$kernel" && test "$newest" != "$kernel" ; then
			echo "cleaning up old kernel: $kernel"
			yum -q -y remove $kernel
			echo
		fi
	done
	echo "adding at job to reboot into the updated kernel: $newest"
	echo shutdown -r now | at now+1 minute
fi

{'fraction_non_alphanumeric': 0.19700876740587933, 'fraction_numerical': 0.013408973697782363, 'mean_word_length': 2.8188976377952755, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7630499', 'n_tokens_mistral': 836, 'n_tokens_neox': 745, 'n_words': 226}