Bash script to read a hostname and separate into variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash script to read a hostname and separate into variables
Prev   Next
# 1  
Old 06-25-2009
Bash script to read a hostname and separate into variables

Hi All,

I'm trying to concoct a bash script to use with a Puppet Implementation that will accept a hostname and break it down into variables.

For example, my hostnames look like this --> machinename-group-building.example.com

I'm looking for a way in the script to read until the first hypen (run it like --> "/usr/bin/hostnamescript machinename-group.building.example.com"), and assign the "machinename" into a variable, read to the second hyphen and assign the "group" into a variable, and then read until the period and assign the "building" into the final variable - disregarding the rest.

What would be the easiest way to tackle this? Thanks!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read variables from a text file for use in csh script

Hello, I have a text file (say, declarevars.txt) that contains multiple lines that are essentially meant to be variable declarations: set arr1 = (var1a var1b var1c) set arr2 = (var2a var2b var2c) . . . I want to be able to read this text file within a csh (sorry) script and have that... (2 Replies)
Discussion started by: arjaydj
2 Replies

2. Shell Programming and Scripting

Problem with variables and bash script

From the command line: dions-air:scripts dion$ ls -l /Users/dion/Library/Application\ Support/Garmin/Devices/3816821036/History/2014-06-07-055251.TCX -rw-r--r-- 1 dion staff 157934 7 Jun 06:55 /Users/dion/Library/Application Support/Garmin/Devices/3816821036/History/2014-06-07-055251.TCXworks... (2 Replies)
Discussion started by: dionbl
2 Replies

3. Shell Programming and Scripting

Shell script to read a file and store in variables

I have a input file like this. Sample.txt 30 | TXDatacenter | TXBackupDC 10 | UKDatacenter | UKBackupDC 0 | NLDatacenter | NLBackupDC ...... ...... ...... I need to get these values in different variables like this. Load1=30 PriCenter1=TXDatacenter... (5 Replies)
Discussion started by: Visha
5 Replies

4. Shell Programming and Scripting

Bash-how to properly READ and PASTE variables.

Recently i made a script for a project at molecular dynamics but am stuck at the last step.The thing i want to do is to ask the user to input the number of particles, then replace the bolded numbers at lines 9 and 17.. code #!/bin/bash #read number of particles echo "insert the number of... (2 Replies)
Discussion started by: arisinhell
2 Replies

5. UNIX for Advanced & Expert Users

Bash script with export variables

Hi all guys, how you can read in thread title, I'm deploying a bash script in which I have to export some variables inside it. But (I think you know) the export command works only inside the script and so, on exit command, the variables aren't set like I set inside the script. Consequently in... (8 Replies)
Discussion started by: idro
8 Replies

6. Shell Programming and Scripting

Multiple Variables for BASH script

Hello, I am new to the whole "scripting" thing. Below is the script that I have so far and where i need the Variables to go (VAR#) #!/bin/bash #Sample Script VAR1= echo "Choose an option: 1) Create a file. 2) Delete a file. 3) Move a file." read VAR1 case $VAR1 in 1) echo "Pick... (4 Replies)
Discussion started by: eclerget
4 Replies

7. Shell Programming and Scripting

problem using variables in bash script

I am using variable to give the location of the file I am using but I get error. Here is the code: LogFile=/tmp/log.email echo -e "could not close the service - error number $error \n" > $LogFile well this is not all the code but is enough because the problem start when I try to use the... (3 Replies)
Discussion started by: programAngel
3 Replies

8. Shell Programming and Scripting

How to make 2 separate arguments in 1 bash script?

This is what I have: #!/bin/bash #ascript.sh WORD1=`tail -n +$1 /home/gscn/word1.txt | head -1` sed -e "s/WORD1/$WORD1/g" < /home/gscn/configtmp > /home/gscn/config WORD2=`tail -n +$1 /home/gscn/word2.txt | head -1` sed -e "s/WORD2/$WORD2/g" < /home/gscn/config2tmp >... (4 Replies)
Discussion started by: guitarscn
4 Replies

9. Shell Programming and Scripting

Read 1-line file and separate into multiple variables

I have one line files with 17 records separated by a semi-colon. I need to create a variable from each record, which I can do via a separate awk for each one, but I know there has to be a better way. Along with pulling out the variable, I need to convert some url coding like a + to a space, etc.... (4 Replies)
Discussion started by: numele
4 Replies

10. Shell Programming and Scripting

Cant separate variables

Hey guys, new problem....im not being able to seperate variables. the code runs like this... OPTIONS=$(awk '{print $2}' /etc/fstab} a=$(zenity --list --text "Mount points selection" --radiolist --column "choice" --column "mountpt" FALSE $OPTIONS); echo $a Note: the result i get is that... (2 Replies)
Discussion started by: dplate07
2 Replies
Login or Register to Ask a Question
HOBBITCLIENT.CFG(5)						File Formats Manual					       HOBBITCLIENT.CFG(5)

NAME
hobbitclient.cfg - Xymon client environment variables DESCRIPTION
Xymon programs use multiple environment variables beside the normal set of variables. For the Xymon client, the environment definitions are stored in the ~xymon/client/etc/hobbitclient.cfg file. Each line in this file is of the form NAME=VALUE and defines one environment variable NAME with the value VALUE. SETTINGS
BBDISP The IP-address used to contact the Xymon server. Default: Chosen when the Xymon client was compiled. BBDISPLAYS List of IP-adresses of Xymon servers. Data will be sent to all of the servers listed here. This setting is only used if BBDISP=0.0.0.0. BBPORT The portnumber for used to contact the Xymon server. Default: 1984. BBHOME The Xymon client top-level directory. Default: The $HOBBITCLIENTHOME setting inherited from the "runclient.sh" script which starts the Xymon client. BBCLIENTLOGS The directory for the Xymon clients' own logfiles. Default: $BBHOME/logs BBTMP Directory used for temporary files. Default: $BBHOME/tmp/ BB Full path to the bb(1) client program. Default: $BBHOME/bin/bb. Commands Many extension scripts expect a series of environment variables to point at various system utilities. These are included in the file when the client is built. INHERITED SETTINGS
Some environment variables are inherited from the "runclient.sh" script which launches the Xymon client: MACHINEDOTS The hostname of the local system. Default: Taken from "uname -n". MACHINE The hostname of the local system, with dots replaced by commas. For compatibility with Big Brother extension scripts. BBOSTYPE The operating system of the local system, in lowercase. Default: taken from "uname -s". HOBBITCLIENTHOME The top-level directory for the Xymon client. Default: The location of the "runclient.sh" script. SEE ALSO
xymon(7) Xymon Version 4.2.3: 4 Feb 2009 HOBBITCLIENT.CFG(5)