CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Finding Unix Logical name(s)

 



zatlas1
User

Oct 27, 2015, 9:03 AM

Post #1 of 13 (2884 views)
Finding Unix Logical name(s) Can't Post

In my facility some machines have one or more logical name(s). I would like to have a way in Perl to find those names, without accessing an external spreadsheet.

I do use:

use Sys::Hostname;

for the physical machine name.

Quite frankly, I was surprised that I could not have found a standard way to do it. Unix exists well above 40 years and Perl is what, over 25 years old, and nobody ever needed that functionality?!



Thank you

ZA


FishMonger
Veteran / Moderator

Oct 27, 2015, 9:56 AM

Post #2 of 13 (2878 views)
Re: [zatlas1] Finding Unix Logical name(s) [In reply to] Can't Post

Sys::Hostname will only return the first name found, not a list.

Besides the possibility of have multiple aliases configured locally, there could also be multiple aliases configured in your dns server.

The first question to ask (yourself) and investigate is how would you retrieve the names from the command line. With that info we can then either look for possible modules that give the same results or call those system commands via backticks or qx() IPC:Run.


zatlas1
User

Oct 27, 2015, 10:13 AM

Post #3 of 13 (2876 views)
Re: [FishMonger] Finding Unix Logical name(s) [In reply to] Can't Post

Well, I resorted to

GetOptions ("machine=s" => \$machine)
or die("Error in command line arguments\n");
die "Please supply logical machine name" if (!$machine);



Which means that I do not allow the program to run if that information is not supplied. However, I cannot prevent the user from supplying the wrong information.



Thank you

ZA


FishMonger
Veteran / Moderator

Oct 27, 2015, 10:21 AM

Post #4 of 13 (2871 views)
Re: [zatlas1] Finding Unix Logical name(s) [In reply to] Can't Post

Right, you can't prevent them from supplying an invalid hostname, but that's where validating user input comes into play.


zatlas1
User

Oct 27, 2015, 10:27 AM

Post #5 of 13 (2869 views)
Re: [FishMonger] Finding Unix Logical name(s) [In reply to] Can't Post

Which brings me back to the original question; in order to validate I need to know what the heck is the logical machine that the user is logged on to?

ZA


FishMonger
Veteran / Moderator

Oct 27, 2015, 11:50 AM

Post #6 of 13 (2861 views)
Re: [zatlas1] Finding Unix Logical name(s) [In reply to] Can't Post

Can you provide more info on what you're needing?

Your opening post implies that you want the user to enter the hostname of the local system (where the script is located), but your last post implies that they're connecting from a remote system and it's the hostname of that system you're wanting.

Maybe we're looking at an XY problem?


(This post was edited by FishMonger on Oct 27, 2015, 11:51 AM)


zatlas1
User

Oct 27, 2015, 12:30 PM

Post #7 of 13 (2855 views)
Re: [FishMonger] Finding Unix Logical name(s) [In reply to] Can't Post

OK, I was not clear. I will give a super simplified version of what I need. The user is logged on to a machine with the logical name 'mymachine' and physical name 'local_server_17', and run on that machine a perl script that looks at some files in some directories (by pre-set criteria)... let's say all files that have the suffix .ksh in all directories that start with /abc. The script looks for some token in those files and spit a csv with these columns:

logical_machine_name, Physical_machine_name,Directory,File_name,Line_number (where the token has been found)



Finding the physical machine name is trivial and so are directory, file name and line number. I also need the logical machine name, but this seems to be unknown inside the machine!!!


FishMonger
Veteran / Moderator

Oct 27, 2015, 12:57 PM

Post #8 of 13 (2852 views)
Re: [zatlas1] Finding Unix Logical name(s) [In reply to] Can't Post

So we're talking about the local station, not a remote system.

Additional hostnames would be configured in the hosts file or dns server. So, besides using SYS::Hostname, you could ping the hostname and/or parse the hosts file, and/or query dns. Each of those options will return an IP address (if resolved) which can be compared to the IP of the local system.

You still haven't explained why you need to do this, which leads me to believe you have an XY problem.


zatlas1
User

Oct 27, 2015, 3:00 PM

Post #9 of 13 (2843 views)
Re: [FishMonger] Finding Unix Logical name(s) [In reply to] Can't Post

OK, Thank you

We need to scan machines and directories for some complicated, program level, dependencies and cross reference the information with information from other sources. Unfortunately, the information is not necessarily uniform. Some use physical and some logical names but most use logical names which is good. The problem is that any logical machine may see a different population of mounts, and thus different directories, which means that each logical machine needs to be scanned on its own.

You have confirmed my suspicion that there is no common way to correlate logical and physical machine. Fortunately, I've got from the administrators an up-to-date and refreshable file that correlate the aforementioned entities, so my business problem is resolved by at large, except that I still have to be careful when running the scan and provide it with an accurate logical name machine which is not easily verifiable.

It still boggles my mind that the information of what logical machine we are running on is not readily available.

I do not know what is an xy problem.

ZA


FishMonger
Veteran / Moderator

Oct 27, 2015, 5:28 PM

Post #10 of 13 (2835 views)
Re: [zatlas1] Finding Unix Logical name(s) [In reply to] Can't Post

Q. "what is an XY problem"

A. https://www.google.com/search?q=what+is+the+xy+problem&ie=utf-8&oe=utf-8


zatlas1
User

Oct 27, 2015, 8:02 PM

Post #11 of 13 (2830 views)
Re: [FishMonger] Finding Unix Logical name(s) [In reply to] Can't Post

Well, indeed this was not an XY question. I did resolve the business need in other ways, but the original question about a common, simple way of finding what is the logical Unix box that one is running on, this was not resolved.

When a process run on a specific logical box, it may see the mounts and directories that are available on that box. Running it on another box, may cause it to see other mounts and it may or may not run on that box. The ability to know the physical box may not be sufficient.

Thanks for answering me anyway
ZA


(This post was edited by zatlas1 on Oct 27, 2015, 8:11 PM)


FishMonger
Veteran / Moderator

Oct 28, 2015, 6:16 AM

Post #12 of 13 (2810 views)
Re: [zatlas1] Finding Unix Logical name(s) [In reply to] Can't Post

When you say "logical box", do you really mean a "virtual box" such as when running VMware?

"logical box" is not the same as "logical name", which is the term you used in your subject and other posts.


zatlas1
User

Oct 28, 2015, 7:14 AM

Post #13 of 13 (2804 views)
Re: [FishMonger] Finding Unix Logical name(s) [In reply to] Can't Post

I am not talking about a virtual box! However, my Unix guy had explained the issue. It is a clustering on Solaris 8 and the only host name I could get is the physical. Once we move to Solaris 10 the problem would disappear.

Thanks, and please mark this as resolved.

ZA

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives