Port incrementing using one file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Port incrementing using one file
# 1  
Old 06-05-2008
Port incrementing using one file

Hi
I wrote this script with the help of you guyz.My next challenge is to increment the port using single file.So far iam using this code to increment hp1 and hp2 .To increment port numbers, iam using two different files (.default_port_hp1 and .default_port_hp2).The challenge for me is to use single file and increment the ports.


-------------
echo -n "Enter hp1 port: "
read hp1
if [ -z $hp1 ]
then

default_port_file=.default_port_hp1
default_port_value=80

get_default_port()
{
if [ -f $default_port_file ]
then
default_port=$(<$default_port_file)
else
default_port=$default_port_value
fi
}
set_default_port() {
if [[ $1 > ${default_port:-$default_port_value} ]]
then
echo $1 > $default_port_file
fi
}
get_default_port
echo "---Using [$default_port] as default port-- : "
read hp1

hp1=${hp1:-$default_port}
echo "Port number used = $hp1"

set_default_port $((hp1+1))
fi

--

echo -n "Enter hp2 port: "
read hp2
if [ -z $hp2 ]
then

default_port_file=.default_port_hp2
default_port_value=443

get_default_port()
{
if [ -f $default_port_file ]
then
default_port=$(<$default_port_file)
else
default_port=$default_port_value
fi
}
set_default_port() {
if [[ $1 > ${default_port:-$default_port_value} ]]
then
echo $1 > $default_port_file
fi
}
get_default_port
echo "---Using [$default_port] as default port-- : "
read https_port

hp2=${hp2:-$default_port}
echo "Port number used = $hp2"

set_default_port $((hp2+1))
fi
----------------

Appreciate your help guyz

--Cool
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing specific and incrementing lines of text from file via variable

This is part of a larger script where I need to pass only 1 line of a file to the script, based on a variable and not a direct reference. As part of a for loop : # for((line=0;line<50;line++)); do # awk ‘NR==$line' PhraseList.txt; done ... (5 Replies)
Discussion started by: Seth
5 Replies

2. UNIX for Beginners Questions & Answers

Incrementing the New File Version Number

Hi, This is my first post here. I am using cygwin on Windows 7. I am starting with a data file with filename "name_1.ext", like "20180831_snapgenotypes_1.csv". The "_1" before ".ext" is a version number. Integers (0-99) are sufficient. They don't have to be like "1.0.0". The filename may... (2 Replies)
Discussion started by: minimalist
2 Replies

3. UNIX for Advanced & Expert Users

Add an incrementing identity column to a file

Two questions: 1) Is there a way to create a new column (i.e. ID) to an existing file containing data and the new column ID populate as an auto incrementing number? for example: (Current file has headers and is PIPE delimited.) **data looks like this** "COL1"|"COL2"|"COL3"|"COL4"|"COL5"... (4 Replies)
Discussion started by: timlisa20
4 Replies

4. UNIX for Advanced & Expert Users

Add an incrementing identity column to a file

Two questions: 1) Is there a way to create a new column (i.e. ID) to an existing file containing data and the new column ID populate as an auto incrementing number? for example: (Current file has headers and is PIPE delimited.) **data looks like this** "COL1"|"COL2"|"COL3"|"COL4"|"COL5"... (0 Replies)
Discussion started by: timlisa20
0 Replies

5. Solaris

How to find port number wwn of particular port on dual port HBA,?

please find the below o/p for your reference bash-3.00# fcinfo hba-port HBA Port WWN: 21000024ff295a34 OS Device Name: /dev/cfg/c2 Manufacturer: QLogic Corp. Model: 375-3356-02 Firmware Version: 05.03.02 FCode/BIOS Version: BIOS: 2.02; fcode: 2.01;... (3 Replies)
Discussion started by: sb200
3 Replies

6. UNIX for Dummies Questions & Answers

Incrementing the New File Version Number

Hello All, In the below script i am trying to check and list the file names, get the last file with highest version number and then increment the version number when i create another file. Example: file1 is COBANK_v1.xml and file2 i want to put it as COBANK_v2.xml, to achieve this i am using awk... (15 Replies)
Discussion started by: Ariean
15 Replies

7. Shell Programming and Scripting

Change numbers in a file, incrementing them

Hello, Here's a file of mine: key1:431 key2:159 key3:998 I need to change these keys to something bigger - and I actually need to shift them all by a range of 3. The output would be: key1:434 key2:162 key3:1001 I can't find the propper sed/awk line that would alter all my... (4 Replies)
Discussion started by: fzd
4 Replies

8. Shell Programming and Scripting

incrementing lines in the file & format output.

Hi All, I need read the file and out put format as below using ksh, I wrote below script its keep on repeating first line in the file. may i know the best way to get the below out put while incrementing line in the file. cat b.txt |awk '{print $0}' |while read line do aa=`cat $line |head -1... (7 Replies)
Discussion started by: ashanabey
7 Replies

9. Shell Programming and Scripting

Port num incrementing

Hello Guyz These days Iam doing pretty good scripting work that is all because of you fellas.Thank you so much. As it goes ,here comes my next problem.Iam trying to implement automatic port number incrementing. For ex: demo() { echo "Enter for default port: read port ... (5 Replies)
Discussion started by: coolkid
5 Replies
Login or Register to Ask a Question