ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a script that I need to run that will reboot a server after a kernel rpm has been installed. the problem is, is that there are several kernels on the server, and I need it to recognize the latest one and then reboot.
Code:
#!/bin/bash
MAX_Time=$(bc <<< '10*60')
RPMage=$(($(date +%s) - $(rpm -qa --queryformat "%{installtime}\n" kernel|head -1)))
if [[ ${RPMage} -lt ${MAX_Time} ]]; then
echo "Rebooting server since package was installed within last 10 Minutes"
/sbin/shutdown -r +2 &
#else
echo "NOT Rebooting server since package was installed over 10 Minutes ago"
fi
Instead of "head -1 " you could use "sort|tail -1" to give the largest (latest) installtime.
You could also consider just checking whether installtime > last boot time (e.g., using btime from /proc/stat). Then you could run your script every 10 minutes from cron.
I am installing an rpm, and I need to check if it has been installed within the last 10 minutes. If so, then I would like to reboot the server. I have used this with other RPM names, the difference has been that there was only one version of the rpm. Now I have 2 or 3 on the system, and I am not sure how to get that info.
I am installing an rpm, and I need to check if it has been installed within the last 10 minutes. If so, then I would like to reboot the server. I have used this with other RPM names, the difference has been that there was only one version of the rpm. Now I have 2 or 3 on the system, and I am not sure how to get that info.
thanks,
What I don't get is if you know you're installing a kernel rpm that will need reboot,
why not install it and reboot in one command?
the script was originally written for a glibc package that was updated for a redhat security alert. the 10 minutes was to give the package time to install.
the install and script are actually run thru a product called HPSA.
the product will install the rpm automatically, and the script will be part of the install policy.
in this way I can push it to a large number of servers with one click. automation...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.