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.
We run both CentOS and Ubuntu here and I need to put together a single shell script with some simple logic to tell the OS's apart and run the appropriate patching/updating commands once that's done and then a reboot. The whole thing will get fired off by crontab at a given date and time for each system.
I've got a few ideas to tell each apart:
For CentOS I found this:
more /etc/system-release
CentOS release 6.9 (Final)
and for Ubuntu I found
uname -a
Linux cnxatlsgi01 4.4.0-75-generic #96-Ubuntu SMP Thu Apr 20 09:56:33 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
but I'm not sure of the best way to do the OS selection or if there is totally better way to go about this. We can't do any automated updating due to processes running the background (fuse) that really hate stuff messing with them when up.
Why?
On the centos server, set up your cron to execute yum
On the Ubuntu, set up your cron to execute apt-get
AFAIK, a reboot is not necessary following an update on CentOS...but I could be wrong about that.
WE have A mix of different types of servers and want one script we can push from a central source to all of then to run at the same time via a cron command where the script will decide which update command to run....now the dirty way to do it just to let it fall through and fail on the systems that don't have the other OS update utilities but I'm trying to not do that. We need and require reboots after every update run here in case a kernel is updated.
I must have been half asleep when I wrote the original request, or the notebooks screen format confused me. The utilities are fine for OS selection:
more /etc/system-release
CentOS release 6.9 (Final)
uname -a
Linux cnxatlsgi01 4.4.0-75-generic #96-Ubuntu SMP Thu Apr 20 09:56:33 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
What I need help with since I know no sed/awk is the selection and if/then portion to decide which group of commands to run based on the given OS type and then end with a reboot and if neither if found exit with out a reboot.
I think the first will do what I need to get this done, need to look at it later, the second does not resolve, 404 error - sorry, looks like its incomplete....ahhh...you went and fixed while I was typing thank you second one there is exactly what I need.
Last edited by gkasica; 05-31-2017 at 07:16 AM.
Reason: typo
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.