unix shell script which inserts some records into a file located in remote servers...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting unix shell script which inserts some records into a file located in remote servers...
# 1  
Old 11-04-2008
unix shell script which inserts some records into a file located in remote servers...

All, I need to write an unix shell script which inserts some records into a file located in remote servers.

* Get the input from the user and insert according the first row. It should be in ascending order.
123451,XA,ABA
123452,XB,ABB
123453,XC,ABC
123455,XE,ABE
123456,XF,ABF
123458,XG,ABG

Now I would like to insert these records "123454,XY,ABD", "123457,XZ,ABZ". I need output like below (ie, file needs to get updated like this)

123451,XA,ABA
123452,XB,ABB
123453,XC,ABC
123454,XY,ABD -- First Record
123455,XE,ABE
123456,XF,ABF
123457,XZ,ABZ -- Second Record
123458,XG,ABG

I need to update the same in different servers at the same time (ie. when I run this script). I'm new to unix shell scripting and now I'm learning.

Can someone help me out with this...many thanks in advance~!
# 2  
Old 11-04-2008
If the file is sorted in numeric order by the first column you can do something like:
Code:
echo "$string" >> file    # append string to the file
sort -n file > newfile    # sort file and redirect output to newfile
mv newfile file           # move newfile to file

Regards
# 3  
Old 11-06-2008
Thanks Franklin, actually I have three fields however I need sort the file based on first column but meanwhile I would like insert the row at last.

For example,

Existing file..

001,a,aaa
002,b,asdewr
002,b,asdaas
002,c,sader
003,r,asdsa
004,l,asdhjie
005,kalsdka

I need to inser these records now...(as per your code, its perfect)

002,c,asdasd

but I also need the output like this:

001,a,aaa
002,b,asdewr
002,b,asdaas
002,c,sader
002,c,asdasd
003,r,asdsa
004,l,asdhjie
005,kalsdka

Please help me...thanks much in advance!


AND Also I need to update the same file (located) in different servers at the same time
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script for remote servers

Hi , I have written a small script : set -x #!/bin/ksh for i in `cat /tmp/list` ( list contains remove servers ) do ssh -t $i << EOF uname -a cd ~user echo "Enter the dir >" read dir path=`ll -ld /home/user/"$dir"` if ; then echo "Dir exists " read rm $path else echo "no such... (9 Replies)
Discussion started by: kpatel786
9 Replies

2. Shell Programming and Scripting

Running set of commands in remote servers in shell script

Hi Wishing to all. I am very new joined in an organization as a unix system administrator. I need a help in preparing a script for a report. i have a file contains all of the linux/ubuntu servers line by line around 140 servers. vi servers.txt nh01 nh02 nh03 bh01 bh04 - - :wq (3 Replies)
Discussion started by: kumaraswamy
3 Replies

3. Shell Programming and Scripting

Comparing file ownership/permission and content of files located on two different servers

Hi All, can some one suggest me a tool to compare file ownership/permission and contents of files located at two different unix servers? Thanks, Pranav (1 Reply)
Discussion started by: Pranav Bhasker
1 Replies

4. Shell Programming and Scripting

Triggering remote UNIX shell script from Remote desktop

I m trying to run a batch script in remote desktop which executes unix commands on the unix server...the problem is i wnt the output in HTML format.so in my batch script i m giving the cmd like ssh hostname path ksh HC_Report.ksh>out.html ...but it generates the HTML file in remote desktop .i... (2 Replies)
Discussion started by: navsan
2 Replies

5. IP Networking

Execute script located on a remote machine

So, is there way of automating this ? My ultimate goal is to run some cmd script in windows and it should connect to a remote unix host and run a script x.sh located on the remote unix host. I was wanting to achieve this by using WinSCP and Putty only. If possible let me know how and if not... (25 Replies)
Discussion started by: mohtashims
25 Replies

6. Shell Programming and Scripting

Problem in appending text to a file located in remote server

ssh -q "server_name sudo echo 'dbagroup::1234' >> sudo /etc/group"if i execute the above code its not getting appended. my requirement is to login to remote server and append dbagroup::1234 in /etc/group i am able to achieve this with tee -a command want to know why its not working with >>... (5 Replies)
Discussion started by: chidori
5 Replies

7. Shell Programming and Scripting

Bash shell script that inserts a text data file into an HTML table

hi , i need to create a bash shell script that insert a text data file into an html made table, this table output has to mailed.I am new to shell scripting and have a very minimum idea of shell scripting. please help. (9 Replies)
Discussion started by: intern123
9 Replies

8. Shell Programming and Scripting

Prevent wrong user from using shell script for multiple remote servers

Hi, I am running a shell script from a central server to multiple remote servers using the following code: application_check() { # Linux/UNIX box with ssh key based login SERVERS=`cat /tmp/server-details` # SSH User name USR="user" # create new file > /tmp/abc.log # connect... (2 Replies)
Discussion started by: mystition
2 Replies

9. Shell Programming and Scripting

Need help to change the content for remote located file

Hi All, I have a file that sits on 4 diffrent servers, those servers are diffrent region based and they are authentication protected and that file has a diff port numbers, so when run the script it must ask my login details,region of server and port no for that file once it took from me it... (1 Reply)
Discussion started by: tmarjuna
1 Replies

10. UNIX for Advanced & Expert Users

Need help to change the content for remote located file

Hi All, I have one file that sits on 4 diffrent servers, those servers are diffrent region based and they are authentication protected and that file has a diff port numbers, so when run the script it must ask my login details,region of server and port no for that file once it took from me... (1 Reply)
Discussion started by: tmarjuna
1 Replies
Login or Register to Ask a Question