[SOLVED] Bash Script to register different host to Spacewalk
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
Bash Script to register different host to Spacewalk
Trying to make this script register host, two different spacewalk servers based on the distro and the last character of it's name.
The first if and elif condition work but after that it doesn't seem to honor the next if conditions. Anyone see what I'm doing wrong?
Even with double quotes it doesn't honor, it will do the systems that hostname ends with "t" but not the "d".
Crazy part is if I make it the first if statement it will work but then another condition a few lines down won't.
Looks like it just gets answered by the first right away. Which shell are you using? Or better yet can you hard code the shell in your script?
e.g.
#!/bin/bash
set -vx
server=`/bin/hostname`
etc..etc..
I ran a test version of your script through #!/bin/bash and #!/bin/sh and worked fine for me. So the only thing I can think of is your shell is not handling your "=" comparison the way you think it is.
In programming, sometimes for example for "=" you need to use "eq" or "==" because "=" is setting a variable, not comparing it.
So depending on what shell you're using, read man page for that shell and see what it expects as a comparison operator for "equals"
Must have been with how the comparison works inside double brackets vs single brackets.
Even after figuring that part out it, didn't like to many if-statements with the double brackets (sounds crazy, I know).
The code below ended up working for me.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.