LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-12-2016, 05:25 PM   #1
gartie
LQ Newbie
 
Registered: Jan 2016
Posts: 6

Rep: Reputation: Disabled
script to reboot server after kernel install


Hello,

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
 
Old 01-13-2016, 11:26 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Firstly, bc is not required as bash can perform integer arithmetic easily.

As to your question, the script tells a slightly different story, as far as I can tell??

Your script appears to be testing how long ago an install was performed, but your question seems related to which version is to be installed?

Would you please clarify which question we are trying to answer?
 
Old 01-13-2016, 11:31 AM   #3
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 172

Rep: Reputation: 56
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.
 
Old 01-13-2016, 11:42 AM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Server + new kernel + automatic anything = epic fail.

Just my opinion.
 
1 members found this post helpful.
Old 01-13-2016, 12:51 PM   #5
gartie
LQ Newbie
 
Registered: Jan 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
what I need to do ...

Hi,

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,
 
Old 01-13-2016, 01:18 PM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by gartie View Post
Hi,

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?
Code:
rpm -[UI]vh /path/or/what/ever.rpm && reboot
rpm package manager surely logs, does it not?

What's the deal with "10 minutes"???
 
Old 01-13-2016, 01:23 PM   #7
gartie
LQ Newbie
 
Registered: Jan 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
reason

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.
 
Old 01-13-2016, 03:52 PM   #8
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
and why the rpm command ?
for a rhel use yum or for suse use zypper
 
Old 01-13-2016, 03:59 PM   #9
gartie
LQ Newbie
 
Registered: Jan 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
why rpm command

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...
 
Old 01-14-2016, 01:38 AM   #10
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
don't forget you will need a script to clean up the mess you've made with the first one.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
DELL 9020 model will reboot after this pc gets kernel & initrd files via PXE server jcky Linux - Newbie 0 03-15-2014 02:45 AM
LXer: Install and Configure Linux Server Using a Bash Script server-easy-install LXer Syndicated Linux News 0 04-28-2012 02:20 PM
frsh centos5.3 install. goes kernel panic after reboot. bangsters Linux - Server 3 07-11-2009 12:12 AM
Kernel 2.6 causes my server to hang on reboot! soulwatcher1974 Linux - Software 2 06-06-2006 10:16 AM
Linux Install - Reboot Loops Forever (Kernel?) Cyber Strike Linux - Newbie 3 01-30-2005 07:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration