FQDN into domain name and hostname


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FQDN into domain name and hostname
# 8  
Old 10-10-2010
Quote:
Originally Posted by danmero
Code:
# cat script
#!/bin/sh
for i in ${@};do echo ${i};done

# /temp/script 1 2 3 4 5 6 7 8 9 10 11
1
2
3
4
5
6
7
8
9
10
11

Actually in this case $i does not contain an enumeration but the parameter values, so it isn't necessary to use curly brackets, but the quotes are necessary to capture arguments that contain space characters..
Code:
for i in "$@";do echo "$i";done

# 9  
Old 10-10-2010
Quote:
Originally Posted by cjcox
awk? Hmmm... I suppose. If portability is the goal (no bash, for example), then use expr or cut or even sed instead (IMHO).

Code:
#Split FQDN into hostname and domain
HOSTNAME=`expr "$7" : '\([^.][^.]*\)\..*'`
DOMAIN=`expr "$7" : '[^.][^.]*\.\(.*\)'`

Or use cut...

Code:
HOSTNAME=`echo "$7" | cut -f1 -d.`
DOMAIN=`expr "$7" | cut -f2- -d.`

or even sed... you're using sed to doctor things up anyhow...

Code:
HOSTNAME=`echo "$7" | sed  's/\..*//'`
DOMAIN=`expr "$7" | sed -n 's/[^.]*\.//p'`

Just my opinion... awk would be my last choice for this.
Code:
HOSTNAME=${7%%.*}
DOMAIN=${7#*.}

This User Gave Thanks to Franklin52 For This Post:
# 10  
Old 10-11-2010
Quote:
Originally Posted by Franklin52
Code:
HOSTNAME=${7%%.*}
DOMAIN=${7#*.}

As I said, and as you mentioned in your post, if you have bash, then it opens up more possibilities (that are even more efficient). It's just not portable, Bourne shell wise.
# 11  
Old 10-11-2010
Quote:
Originally Posted by cjcox
As I said, and as you mentioned in your post, if you have bash, then it opens up more possibilities (that are even more efficient). It's just not portable, Bourne shell wise.
This is portable with bash, ksh and all POSIX shells, on a SUN OS perhaps with /usr/xpg4/bin.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Named resolving old fqdn on AIX after change to new fqdn.

Hey All, We have defined abc.this.that in: /etc/named.conf and corresponding files but after the change that we verified through dig -x this.that ptr all is resolving correctly. However in the /var/log/named/named.log file we still see entries for: 4-May-2015 12:15:30.390 queries:... (6 Replies)
Discussion started by: Devyn
6 Replies

2. UNIX for Dummies Questions & Answers

Postfix Configuration:Hostname/Domain Name Doubts

I have a RHEL server where I want to create a mail server so I can send myself alerts whenever X process have problems. Disclaimer: Im a programmer thats been forced to do IT. So I'm trying my best here. The problem: While configuring Postfix it asks for $myhostname which apparently must be... (2 Replies)
Discussion started by: RedSpyder
2 Replies

3. UNIX for Dummies Questions & Answers

nLocal sendmail issues when hostname not set in official domain name

Hi, I'm having issues with sendmail when I try to send host to host mail. I've had to change the "my official domain name" line to mycompany.com to get the mails through the external spam filter, when a mail was sent with hostname.mycompany.com it was blocked. I had to change the Dj macro... (0 Replies)
Discussion started by: elcounto
0 Replies

4. 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

5. Shell Programming and Scripting

how to get the FQDN

Suppose I am in one server A .I want to know the FQDN of another host B then how can I get the FQDN of that host B from host A. (1 Reply)
Discussion started by: maitree
1 Replies

6. UNIX for Dummies Questions & Answers

My domain name as my IRC hostname?

When I connect to any IRC server, it's usually my ISP IP address/hostname. I own a domain, but I'm not using it for anything (no web hosting service or server). Is it possible for me to use my domain as my IRC hostname instead of my regular ISP hostname? (0 Replies)
Discussion started by: guitarscn
0 Replies

7. Windows & DOS: Issues & Discussions

How to: Linux BOX in Windows Domain (w/out joining the domain)

Dear Expert, i have linux box that is running in the windows domain, BUT did not being a member of the domain. as I am not the System Administrator so I have no control on the server in the network, such as modify dns entry , add the linux box in AD and domain record and so on that relevant. ... (2 Replies)
Discussion started by: regmaster
2 Replies

8. Solaris

List of Hostname under NIS Domain

How do I find a list of hosts under a domainname on a NIS+ I did check nisls command , I could not find any ??? (5 Replies)
Discussion started by: sriram003
5 Replies

9. 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

10. Programming

FQDN and getdomainname

I have a need to create a connection between an erlang node and my C program. the name of an erlang node looks something like monitor@host1.ipc.co.za. The piece of code I have to construct a node name looks like this: char *hostname, *domainname, *nodename = "monitor", *thisfullnodename; ... (1 Reply)
Discussion started by: NanoSec
1 Replies
Login or Register to Ask a Question