Sponsored Content
Full Discussion: Hostname in Perl?
Top Forums Shell Programming and Scripting Hostname in Perl? Post 302362679 by jp2542a on Friday 16th of October 2009 10:28:51 PM
Old 10-16-2009
Code:
#!/usr/bin/perl

$var = `hostname`;
@alist = split(/\./, $var) ;
print $alist[1];



---------- Post updated at 07:28 PM ---------- Previous update was at 07:21 PM ----------

Or using Frank's suggestion:

Code:
#!/usr/bin/perl
use Sys::Hostname;
$var = hostname;
@alist = split(/\./, $var) ;
print $alist[1];

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Hostname

Hello, I am installing redhat linux 6.2 on an intel based system. Whether i want to know any naming conventions should i follow. ie Any convention to follow to name a linux machine(To give hostname). Simillarly for domain name also. Please suggest in this regard (1 Reply)
Discussion started by: bache_gowda
1 Replies

2. IP Networking

looking up hostname

Using Solaris 8 (or WINXP). I am trying to look up a specific DNS hostname, but I don't know which DNS server houses that entry. How can I find the hostname? nslookup gives me the following: C:\>nslookup hostname Server: dnsserver Address: x.x.x.x *** dnsserver can't find hostname:... (2 Replies)
Discussion started by: dangral
2 Replies

3. HP-UX

Change IP and Hostname

Hello.. I wanted to know how to change IP and Hostname on HPUX system, and I don't want to make it as NIS master either. Could someone tell me the files I need to modify and make sure it's on network? Thanks! :o (3 Replies)
Discussion started by: catwomen
3 Replies

4. UNIX for Dummies Questions & Answers

change hostname

Hi, I asked this question whenI was running solaris 8 and got some very good answers. I've just uograded to Solaris 10 and there seems to quite a few changes so I need to know again. https://www.unix.com/showthread.php?t=8547 ------------ Hi (now solaris 10) I know how to change the... (2 Replies)
Discussion started by: fishman2001
2 Replies

5. UNIX for Dummies Questions & Answers

Solaris - unknown hostname - how can I change hostname?

Hello, I am new to Solaris. I am using stand alone Solaris 10.0 for test/study purpose and connecting to internet via an ADSL modem which has DHCP server. My Solaris is working on VMWare within winXP. My WinXP and Solaris connects to internet by the same ADSL modem via its DHCP at the same... (1 Reply)
Discussion started by: XNOR
1 Replies

6. UNIX for Advanced & Expert Users

What hostname is a client using?

Is there a way to find out what name a client is using to connect to a server? For example: client is telnet'ing or ftp'ing to Server B.domain.com, using name C.domain.com. (B and C resolve to the same IP). Can we, on the server B find out that the client used C.domain.com to connect? I have tried... (1 Reply)
Discussion started by: mugambo
1 Replies

7. Shell Programming and Scripting

mailx and hostname

Hi how to include the hostname in the subject of an email send by mailx? mailx -s "here goes the subject `uname -n`" abc@xyz.com or `hostname` list the words as is thank you (1 Reply)
Discussion started by: melanie_pfefer
1 Replies

8. UNIX for Dummies Questions & Answers

get the server's hostname

i read that if i issue : cat /etc/sysconfig/network > textfile i will be able to determine the hostname of the server that my linux workstation is connected to. but there are several other lines outputted that i do not need. i just need the hostname part. is there any other unix... (2 Replies)
Discussion started by: mbaste2
2 Replies

9. Emergency UNIX and Linux Support

HP UX - ILO Console hostname different than Machine Hostname...

Hi All, So we added a new HP-UX 11.31 machine. Copied OS via Ignite-UX (DVD)over from this machine called machine_a. It was supposed to be named machine_c. And it is when you log in...however when I'm in the ILO console before logging in, it says: It should say: What gives? And how do... (4 Replies)
Discussion started by: zixzix01
4 Replies

10. UNIX for Advanced & Expert Users

Hostname -f hostname: Unknown host

deleted (0 Replies)
Discussion started by: hce
0 Replies
CALLBACK(3)						     Library Functions Manual						       CALLBACK(3)

NAME
callback - closures with variable arguments as first-class C functions SYNOPSIS
#include <callback.h> void function (data, alist) void* data; va_alist alist; { va_start_type(alist[, return_type]); arg = va_arg_type(alist[, arg_type]); va_return_type(alist[[, return_type], return_value]); } callback = alloc_callback(&function, data); free_callback(callback); is_callback(callback) callback_address(callback) callback_data(callback) DESCRIPTION
These functions implement closures with variable arguments as first-class C functions. Closures as first-class C functions means that they fit into a function pointer and can be called exactly like any other C function. More- over, they can be called with variable arguments and can return variable return values. callback = alloc_callback(&function, data) allocates a callback. When callback gets called, it arranges to call function, passing data as first argument and, as second argument, the entire sequence of arguments passed to callback. Function calling conventions differ considerably on different machines, therefore the arguments are accessed and the result value is stored through the same macros as used by the vacall package, see below. The callbacks are functions with indefinite extent: callback is only deallocated when free_callback(callback) is called. is_callback(callback) checks whether the C function callback was produced by a call to alloc_callback. If this returns true, the arguments given to alloc_callback can be retrieved: callback_address(callback) returns &function, callback_data(callback) returns data. VACALL MACROS
Within function, the following macros can be used to walk through the argument list and specify a return value: va_start_type(alist[, return_type]); starts the walk through the argument list and specifies the return type. arg = va_arg_type(alist[, arg_type]); fetches the next argument from the argument list. va_return_type(alist[[, return_type], return_value]); ends the walk through the argument list and specifies the return value. The type in va_start_type and va_return_type shall be one of void, int, uint, long, ulong, longlong, ulonglong, double, struct, ptr or (for ANSI C calling conventions only) char, schar, uchar, short, ushort, float, depending on the class of return_type. The type specifiers in va_start_type and va_return_type must be the same. The return_type specifiers passed to va_start_type and va_return_type must be the same. The type in va_arg_type shall be one of int, uint, long, ulong, longlong, ulonglong, double, struct, ptr or (for ANSI C calling conventions only) char, schar, uchar, short, ushort, float, depending on the class of arg_type. In va_start_struct(alist, return_type, splittable); the splittable flag specifies whether the struct return_type can be returned in regis- ters such that every struct field fits entirely in a single register. This needs to be specified for structs of size 2*sizeof(long). For structs of size <= sizeof(long), splittable is ignored and assumed to be 1. For structs of size > 2*sizeof(long), splittable is ignored and assumed to be 0. There are some handy macros for this: va_word_splittable_1 (type1) va_word_splittable_2 (type1, type2) va_word_splittable_3 (type1, type2, type3) va_word_splittable_4 (type1, type2, type3, type4) For a struct with three slots struct { type1 id1; type2 id2; type3 id3; } you can specify splittable as va_word_splittable_3 (type1, type2, type3) . NOTES
Functions which want to emulate Kernighan & Ritchie style functions (i.e., in ANSI C, functions without a typed argument list) cannot use the type values char, schar, uchar, short, ushort, float. As prescribed by the default K&R C expression promotions, they have to use int instead of char, schar, uchar, short, ushort and double instead of float. The macros va_start_longlong(), va_start_ulonglong(), va_return_longlong(), va_return_ulonglong(), va_arg_longlong() and va_arg_ulonglong() work only if the C compiler has a working long long 64-bit integer type. The struct types used in va_start_struct() and va_struct() must only contain (signed or unsigned) int, long, long long or pointer fields. Struct types containing (signed or unsigned) char, short, float, double or other structs are not supported. SEE ALSO
vacall(3), trampoline(3). BUGS
The current implementations have been tested on a selection of common cases but there are probably still many bugs. There are typically built-in limits on the size of the argument-list, which may also include the size of any structure arguments. The decision whether a struct is to be returned in registers or in memory considers only the struct's size and alignment. This is inaccu- rate: for example, gcc on m68k-next returns struct { char a,b,c; } in registers and struct { char a[3]; } in memory, although both types have the same size and the same alignment. <callback.h> cannot be included when <varargs.h> or <stdarg.h> is included. (Name clash for va_alist.) The argument list can only be walked once. NON-BUGS All information is passed in CPU registers and the stack. The callback package is therefore multithread-safe. PORTING
Porting callback consists in first porting the vacall and trampoline packages, then choosing a CPU register for passing the closure from trampoline to vacall. This register is normally the register designated by STATIC_CHAIN_REGNUM in the gcc source, file gcc-2.7.2/con- fig/cpu/cpu.h. AUTHOR
Bruno Haible <bruno@clisp.org> ACKNOWLEDGEMENTS
Many ideas were cribbed from the gcc source. 14 January 2001 CALLBACK(3)
All times are GMT -4. The time now is 02:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy