Sponsored Content
Top Forums Shell Programming and Scripting Bash: How to use read with conditions & loops Post 302983587 by Arnaudh78 on Thursday 13th of October 2016 12:48:49 PM
Old 10-13-2016
Hi, thanks to you both for the solutions SmilieSmilie I make a script for a basic installation of a servers, here the beginning, if anyone is interested and if you have some critics or advices don't hesitate, it will be beneficial to me :
1st step, I have created a file with a template from an interface file, named choice_interfaces.txt :
Code:
#--------------------------------------------------------------
# The loopback network interface
#--------------------------------------------------------------

auto lo
iface lo inet loopback

#--------------------------------------------------------------
# Eth0
#--------------------------------------------------------------
auto eth0
iface eth0 inet static

2nd step, I have created another file with my script :
Code:
#!/bin/bash

#!/bin/bash
fetchip() {
  printf "%s: " "$1"
  until
    read
    [[ "$REPLY" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]] &&
    {
    IFS=. read ip1 ip2 ip3 ip4 <<< "$REPLY"
    [[ $ip1 -le 255 && $ip2 -le 255 && $ip3 -le 255 && $ip4 -le 255 ]]
    }
  do
    printf "Invalid $1 IP address - Please re-enter\n%s: " "$1"
  done
}

cp /home/scripts/choice_interfaces.txt /home/scripts/interfaces.txt
chmod 644 /home/scripts/interfaces.txt

echo -e "Please enter the network informations into the /etc/network/interfaces file, complete them below :\n"

sed -n '1,10p' choice_interfaces.txt

fetchip address
fetchip network
fetchip netmask
fetchip broadcast
fetchip gateway

sed -i '12s/$/\n address '$address'/' interfaces.txt
sed -i '13s/$/\n network '$network'/' interfaces.txt
sed -i '14s/$/\n netmask '$netmask'/' interfaces.txt
sed -i '15s/$/\n broadcast '$broadcast'/' interfaces.txt
sed -i '16s/$/\n gateway '$gateway'/' interfaces.txt

#mv /home/scripts/interfaces.txt /etc/network/interfaces

on this, see you later SmilieSmilie

Last edited by Arnaudh78; 10-13-2016 at 02:32 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

if statement with two conditions -e, &&

Wow I'm so zoned out I don't even know if I posted this question up already (I couldn't find it in my book marks or in "yesterday's" post). My question is, I'm writing a korn script that does something like the following, but I don't yet completely understand the syntax. I need to check that... (16 Replies)
Discussion started by: yongho
16 Replies

2. Shell Programming and Scripting

scripting headache... loops & variables

Surely there's an easier way to do this, lets see if anyone knows! I am new to scripting so go easy on me! I have the following script and at the moment it doesn't work and I believe the problem is that I am using a while loop within a while loop. When I run the script using sh -x I can see... (6 Replies)
Discussion started by: StevePace
6 Replies

3. Shell Programming and Scripting

multiple conditions in if using && operator

VARIABLE="project" if && ] then echo "VARIABLE is not empty" fi this is not working what is wrong in the syntax?? (2 Replies)
Discussion started by: codeman007
2 Replies

4. Shell Programming and Scripting

Bash Script to Read & Write on different directories

Hi, root@server] df -h 121G 14G 101G 12% /home 147G 126G 14G 91% /backup We having our site files and images are storing in /backup/home/user/files/ through symbolic link created in /home directory pointing in /backup directory as following. root@server] cd /home... (1 Reply)
Discussion started by: mirfan
1 Replies

5. Shell Programming and Scripting

PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP. I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Discussion started by: lowmaster
0 Replies

6. UNIX for Dummies Questions & Answers

Faster than nested while read loops?

Hi experts, I just want to know if there is a better solution to my nested while read loops below: while read line; do while read line2; do while read line3; do echo "$line $line2 $line3" done < file3.txt done < file2.txt done < file1.txt >... (4 Replies)
Discussion started by: chstr_14
4 Replies

7. Shell Programming and Scripting

bash loops

hello i'm writing a script and I want to use a for loop inside a while loop as following: while read line; do echo $line for i in $vrm; do echo $i done done < './contacts' when i use just the while loop it prints the lines from file ./contacts just... (13 Replies)
Discussion started by: vlm
13 Replies

8. Shell Programming and Scripting

GNU & BSD Makefile Directives & Conditions Compatibility

Firstly, I would like to apologize if this is not the appropriate sub-forum to post about GNU/BSD makefile scripting. Though my code is in C++, because I am focusing on the makefile I thought it would go better in shell scripting. Please correct me if I am wrong. Secondly, I am not interested in... (0 Replies)
Discussion started by: AntumDeluge
0 Replies

9. Shell Programming and Scripting

[Bash] Read History function & Read Arrowkeys

Hi. How can I create a history function? (By "read" command or so) & How can I configure a read command so that the arrow keys are not displayed so funny? (^[[A) Thanks in advance. (4 Replies)
Discussion started by: sinnlosername
4 Replies

10. UNIX for Dummies Questions & Answers

Loops & Variable

I am using this code: for e in {1..14} do awk '{gsub(/^.*GGGGGG|TTTTT.*$/,"",$0)} 1' $e.1 > ${e}.2 done However, in the second loop instead of GGGGGG|TTTTT, I should use AAAAAA|CCCCCC. For third loop CCAAAA|CCCCAA, so on and so forth. Is there any way to accomplish this without writing... (20 Replies)
Discussion started by: Xterra
20 Replies
dibbler-client(8)						      Dibbler							 dibbler-client(8)

NAME
dibbler-client - a portable DHCPv6 client DESCRIPTION
dibbler-client is a portable implementation of the DHCPv6 client. It supports both stateful (i.e. IPv6 address granting) and stateless (i.e. options granting) autoconfiguration. There are ports available for Linux 2.4/2.6 systems as well as MS Windows XP and 2003. They are freely available under GNU GPL version 2 (or later) license. SYNOPSIS
dibbler-client [ run | start | stop | status | install | uninstall ] OPTIONS
run - starts client in the console. Client can be closed using ctrl-c. start - starts client in daemon mode. stop - stops running clients. status - shows status of the client and server. install - installs client as a service. This is not implemented yet. uninstall - uninstall client service. This is not implemented yet. EXAMPLES
Let's start with simple configuration. We want receive one IPv6 address and there is only one Ethernet interface present. In that case client.conf file might be completly empty. Dibbler client will request for one IPv6 address on each up, running and multicast capable interface (except loopback). Now some real example. We want one IPv6 address and receive DNS servers and domain name. We are also not interested in the details, so debug mode is disabled. log-mode short log-level 6 iface eth0 { ia { } option dns-server option domain } Next example: we want only NIS domain and NIS server information. That information should be periodicaly renewed, so we use lifetime option. We don't need any addresses so stateless mode is used. log-mode short iface eth0 { stateless option nis-server option nis-domain option lifetime } More examples can be found in the User's Guide. FILES
All files are created in the /var/lib/dibbler directory. Dibbler client reads /var/lib/dibbler/client.conf file. During operation, Dibbler saves various file in that directory. After reception of the DNS servers or domain informations, they are added to the /etc/resolv.conf file. After shutdown, that information is removed from that file. Option values are stored in the option-* files. Log file is named client.log. STANDARDS
This implementation aims at conformance to the following standards: RFC 3315 DHCP for IPv6 RFC 3319 SIP options for DHCPv6 RFC 3646 DNS server options for DHCPv6 RFC 3736 Stateless DHCPv6 RFC 3898 NIS options for DHCPv6 Also options specified in following drafts are implemented: draft-ietf-dhc-dhcpv6-opt-timeconfig-03.txt NTP and timezone options. draft-ietf-dhc-dhcpv6-opt-lifetime-00.txt Option renewal. BUGS
Bugs are tracked with bugzilla, available at http://klub.com.pl/bugzilla/. If you belive you have found a bug, don't hesitate to report it. AUTHOR
Dibbler was developed as master thesis on the Technical University of Gdansk by Tomasz Mrugalski and Marek Senderski. Currently Marek has not enough free time, so this project is being developed by Tomasz Mrugalski. Authors can be reached at thomson@klub.com.pl and msend@o2.pl SEE ALSO
There is dibbler-server(8) manual page. You are also advised to take a look at project website located at http://klub.com.pl/dhcpv6/. As far as authors know, this is the only Windows DHCPv6 stateful implementation available. It is also one of two freely available under Linux. The other Linux implementation is available at http://dhcpv6.sourceforge.net, but it is rather outdated and seems not being actively devel- oped. GNU
2004-12-11 dibbler-client(8)
All times are GMT -4. The time now is 05:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy