Comments 10 Posted In Red Hat Enterprise Linux Run script automatically after kernel upgrade ? Latest response 2014-10-01T07:17:52+00:00 We would like to run our site specific scripts after each kernel upgrade. But would like to do it automatically. Is it possible somehow to do that ? Regards p. Started 2014-09-30T15:41:32+00:00 by firstname.lastname@example.org Pro 717 points Log in to join the conversation Responses Sort By Oldest Sort By Newest Active Contributor 210 points 30 September 2014 7:39 PM Alex Alexzander maybe use uname -r in a test condition to see if it is changed or of a higher numeric value. Just thinking out loud. Perhaps a cron job that tests this once a day for changes? PP Newbie 19 points 30 September 2014 9:53 PM Philip Perry I would roll a custom rpm package and put your script in the %triggerin section. This also makes it easy to deploy (and update) your site specific scripts across your site. Guru 3501 points 30 September 2014 10:00 PM Akemi Yagi Very good suggestion. Here's a useful link to learn about %triggerin: http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch10s02.html PP Newbie 19 points 30 September 2014 10:03 PM Philip Perry For example: %triggerin -- kernel place script here to run whenever package "kernel" is installed For more information, see here: http://rpm.org/api/18.104.22.168/triggers.html Note: the kernel package isn't normally updated in rpm terms, but is normally treated as a new install with an older kernel package typically being uninstalled. This behaviour is described in yum. p. Pro 717 points 1 October 2014 7:23 AM email@example.com Philip, this solution seems promising and most sophisticated. Do you use this solution ? p. Pro 717 points 3 October 2014 9:01 AM firstname.lastname@example.org Hi Philip, I have implemented your solution and it works like a charm. Thanks :-) Guru 6863 points 30 September 2014 10:10 PM email@example.com Community Leader I have made one assumption: you would like to do this after the host is updated and rebooted? If I was in this position.. I would likely do the following: create a "touch file" in the kernel directory of the running kernel at the end of your script When the host reboots, it runs: /etc/init.d/check_for_new_kernel #!/bin/bash # Exit script if the file matches the running kernel test -f /lib/modules/`uname -r`/.isupdated && exit 0 # If last test failed, then run the following: (if successful, create new touch file, else exit 9) /root/bin/update_after_kernel_upgrade.sh && touch /lib/modules/`uname -r`/.isupdated || exit 9 exit 0 You could either put that touch command in your update_script, or leave it in the check script (or both, I suppose). If you don't have the kernel-devel package installed, you could do the same but change the location to somewhere else... touch /root/.`uname -r` or.. touch /var/lib/.`uname -r` I would put it somewhere that would not be impacted by a cleanup script or something. p. Pro 717 points 1 October 2014 7:21 AM firstname.lastname@example.org James, it should be run after kernel upgrade but before reboot. The script will update rc* scripts to include 3rd party software (which disappear after kernel upgrade). Guru 6863 points 1 October 2014 12:09 PM email@example.com Community Leader I use something similar as the example I had given to update VMware tools on our VMs. If the host comes up and can't find the modules for the kernel that was started, then run the vmware tools installation. It's not "bullet proof" - but it's fairly solid for what we need. p. Pro 717 points 1 October 2014 7:17 AM firstname.lastname@example.org Hi all, thanks for your suggestions. I was hoping to have something like dkms in Debian or just plain config file (which I wasn't aware of so far ...) where I could set it up.