UNIX Shell Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting UNIX Shell Script
# 1  
Old 08-13-2015
UNIX Shell Script

Hi I need a shell script
My requirement is something like adding entries to a file
Code:
cat fielname will have below 5 lines
ServerName:Test
Connection Attempt:yes
Connection retries:3
Max Sessions:5
Communication address:172.24.3.11

I have one such entry in a file.
Say i want to add more such entry with servername and Communication address going to change values and other variables remain same.

I want to device a script like i will grep for servername and if server name is present i will exit the script
if servername is not present i add a new entry
followed by communication address

my final file should be like this
Code:
ServerName:Test
Connection Attempt:yes
Connection retries:3
Max Sessions:5
Communication address:172.24.3.11

new entry added
ServerName:Test1
Connection Attempt:yes
Connection retries:3
Max Sessions:5
Communication address:172.24.3.12

Moderator's Comments:
Mod Comment Please use code tags for your data and code next time! Thanks

Last edited by vbe; 08-14-2015 at 06:41 AM..
# 2  
Old 08-13-2015
What have you tried?
# 3  
Old 08-13-2015
I tried using grep "Test" filename (where one single entry is available)
Code:
if [[ $? -eq 0 ]]; then
echo "Servername Test is present"
else 
echo "Add server entry"
fi

---------- Post updated at 03:52 PM ---------- Previous update was at 03:52 PM ----------

i am just spitballing, i need to add the ip address as well.

Last edited by vbe; 08-14-2015 at 06:42 AM.. Reason: code tags!!
# 4  
Old 08-13-2015
Why would you need the IP Address?
Doesn't DNS work?

But based on your original requirements, what you wrote is nearly correct:
Code:
if ! grep -q "^ServerName: ${NAME}" filename; then
    echo ${NAME}: add entry
fi

Using grep "Test" filename may result in false positives if the hostname matches a tag, such as "max".
# 5  
Old 08-14-2015
It is a script for Connect Direct file transfer and i am trying to automate the update netmap entry so that i don't have to manually enter the server node and ip address.
The server and the communication address change everytime a new server is being added.
# 6  
Old 08-14-2015
So - what exactly is the problem, now?
# 7  
Old 08-14-2015
I am not able to complete the script,
I need to add the servername and the communication address.

---------- Post updated at 12:46 PM ---------- Previous update was at 12:45 PM ----------

say like the server entry is added on the 1st line of the contents
Communication address is on added on5,6 th line of the contents
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass Oracle sql script as argument to UNIX shell script?

Hi all, $ echo $SHELL /bin/bash Requirement - How to pass oracle sql script as argument to unix shell script? $ ./output.sh users.sql Below are the shell scripts and the oracle sql file in the same folder. Shell Script $ cat output.sh #!/bin/bash .... (7 Replies)
Discussion started by: a1_win
7 Replies

2. Shell Programming and Scripting

Batch script to execute shell script in UNIX server

Hi team, My requirement is to transfer pdf files from windows machine to unix server and then from that unix server we should sftp to another server. I have completed the first part i.e From windows to using to unix server with the help of psftp.exe code: psftp user@host -pw password <... (1 Reply)
Discussion started by: bhupeshchavan
1 Replies

3. Shell Programming and Scripting

How can i run sql queries from UNIX shell script and retrieve data into text docs of UNIX?

Please share the doc asap as very urgently required. (1 Reply)
Discussion started by: 24ajay
1 Replies

4. Shell Programming and Scripting

Dos batch script to execute unix shell script

Can anyone help me with a dos batch script to execute a shell script residing in an unix server. I am not able to use ssh. Thanks in advance (2 Replies)
Discussion started by: Shri123
2 Replies

5. Shell Programming and Scripting

FTP from windows to unix server using unix shell script

Hi, Is it possible to ftp a huge zip file from windows to unix server using unix shell scripting? If so what command i need to use. thanks in advance. (1 Reply)
Discussion started by: Shri123
1 Replies

6. Shell Programming and Scripting

(Urgent):Creating flat file using sql script and sqlplus from UNIX Shell Script

Hi, I need help urgently for following issue. Pls help me to resolve this issue. I am calling sql script file(file1.sql) from UNIX Shell Script(script1.ksh) using sql plus and trying to create flat file that contains all records returned from SQL query in SQL script(file1.sql) I given... (6 Replies)
Discussion started by: praka
6 Replies

7. Shell Programming and Scripting

help me in sending parameters from sqlplus script to unix shell script

Can anybody help me out in sending parameters from sql*plus script to unix shell script without using flat files.. Initially in a shell script i will call sql*plus and after getting some value from some tables, i want that variable value in unix shell script. How can i do this? Please tell me... (2 Replies)
Discussion started by: Hara
2 Replies

8. Shell Programming and Scripting

check in unix shell script so that no one is able to run the script manually

I want to create an automated script which is called by another maually executed script. The condition is that the no one should be able to manually execute the automated script. The automated script can be on the same machine or it can be on a remote machine. Can any one suggest a check in the... (1 Reply)
Discussion started by: adi_bang76
1 Replies

9. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies

10. Shell Programming and Scripting

How to run unix commands in a new shell inside a shell script?

Hi , I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell. So scenario is that - I need to have one shell script which is ran as a part of crontab - in this shell script I need to do a... (2 Replies)
Discussion started by: hkapil
2 Replies
Login or Register to Ask a Question