nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

access file from remote location and save it

This is a discussion on access file from remote location and save it within the Shell scripting forums, part of the Development/Scripting category; Hi I've a file called abc and the same file on a remote machine. Both files have the same data. ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 28-09-2009, 09:38 PM
Senior Member
User
 
Join Date: Jul 2006
Posts: 145
Thanks: 0
Thanked 2 Times in 2 Posts
Rep Power: 4
asim.mcp is on a distinguished road
Default access file from remote location and save it

Hi


I've a file called abc and the same file on a remote machine. Both files have the same data. I've to edit these file one by one to update data in these files.


Is there any possibility that i could enter data in both simultaneously from one location??




Regards
Asim
Reply With Quote
  #2 (permalink)  
Old 29-09-2009, 12:30 AM
jaysunn's Avatar
Powered By Linux
User
 
Join Date: Apr 2009
Location: 41.332032,-73.089775
OS: RHEL - OSX
Scripting language: BASH - Learning Ruby
Posts: 602
Thanks: 61
Thanked 80 Times in 72 Posts
Rep Power: 10
jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold
Default

Sure,

I am assuming you are using linux. You achieve this with ssh and a for loop. This is a bash script.

Give this a try. Please add the server names in place of server1 and server2 if you do not have NIS or the /etc/hosts files showing them, add the servers IP addresses in that spot. You can also setup ssh keys to take care of typing the passwords each time the script is invoked.


Create a file with the text below in it.

Code:
Prompt>vi filechange.sh
Add the code below after you change the server names to your servers or IP addresses. Make the script executable:

Code:
Prompt>chmod +x filechange.sh
You will need to be root for all of this, or use the sudo call before each command.

Now execute with:

Code:
Prompt>/path/to/script/filechange.sh
PHP Code:
#! /bin/bash


for server in "server1" "server2"  ;  do    

ssh $server echo "text that you want to change"  >> /path/to/file/ ;  done 
This solution will only inject text into a file. If you need to do a replace of some sort you can use something like this:

PHP Code:
#! /bin/bash


for server in "server1" "server2"  ;  do    

ssh $server echo /path/to/file sed -'s/replace-text-with/new-text-string/g' ;  done 

Be careful with the sed -e option cause this will change the file on the fly. And there will be no backup. Be sure to back up all files before trying any of this.


Also please give a bit more detail in regards to what you need to edit or change on the files. I can taylor the script to your needs. As always this is just my suggestion. There are many other ways most likely.

Jaysunn
__________________
Have a look at what I have been working on
http://www.shellasaurus.com
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Save every fifth file Mats Shell scripting 3 09-06-2008 08:45 PM
Remote access to linux server RamPD Linux software 9 26-05-2008 07:21 AM
Command line remote access angelus_kit Networking, Firewalls and Security 7 05-09-2007 06:30 PM
MySQL remote server access howto raj Databases servers 0 29-07-2007 05:32 AM
Remote CVS Access rajuk Linux software 4 20-10-2006 10:41 AM


All times are GMT +5.5. The time now is 05:26 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38