executing sed on a remote server


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting executing sed on a remote server
# 1  
Old 01-12-2011
executing sed on a remote server

Hi
I am trying to edit a text file on a remote server using sed from within a cygwin shell on a windows system.

Code:
$ sed -i  "s/aaa/bbb/g"  \\remoteHost\c$\log.info 
sed: can't read \remoteHostc$log.info: No such file or directory

What am I missing ?
Thanks.

Last edited by Scott; 01-12-2011 at 03:36 PM.. Reason: Code tags, please...
# 2  
Old 01-12-2011
And if you type ls \\remoteHost\c$\log.info (or dir \\remote...) what do you see?
# 3  
Old 01-12-2011
$ls \\remoteHost\c$\log.info
\remoteHostc$log.info

vnn@myHost /cygdrive/c
$dir \\remoteHost\c$\log.info
\remoteHostc$log.info
vnn@myHost /cygdrive/c

---------- Post updated at 02:56 PM ---------- Previous update was at 02:49 PM ----------

From my windows local system, from a command prompt, I am able to see this file on the remote server using 'dir' command.
Also
an echo command seems to work from within the cygwin shell on my local windows system
echo "xxx" >> \\remoteHost\c$\log.info

It looks like the problem is specific to sed...
# 4  
Old 01-12-2011
Does:

Code:
sed  "s/aaa/bbb/g" \\remote.....

(without -i) work?

Is it that you haven't set up write permissions to the remote directory / file?

edit: your updated post crossed mine! If the echo works, you have write permission Smilie
# 5  
Old 01-13-2011
no the sed command without -i does not work either.
sed: can't read \remoteHostc$log.info: No such file or directory

---------- Post updated at 10:07 PM ---------- Previous update was at 03:30 PM ----------

Tried sed "s/aaa/bbb/g" \\remoteHost\c$\log.info > \\remoteHost\c$\temp\log.txt
Substitution was successful but \\remote...\temp\log.txt contained all the lines in log.info minus the newlines. All of the content in log.txt was in a single line...

---------- Post updated 01-13-11 at 11:38 AM ---------- Previous update was 01-12-11 at 10:07 PM ----------

After running sed "s/aaa/bbb/g" \\remoteHost\c$\log.info > \\remoteHost\c$\temp\log.txt
I noticed that notepad displayed log.txt file contents in one line. It appears that wehn the file is modified from the cygwin shell, it adds both the carriage return and newline between the lines instead of just the newlines.

How can I edit a file on the remote windows server in place and have just newlines inserted between the lines ?
Thanks.

---------- Post updated at 11:49 AM ---------- Previous update was at 11:38 AM ----------

I piped the output of "s/aaa/bbb/g" \\remoteHost\c$\log.info to sed 's/$`"/\\r/" and that took care of converting Unix style newlines to dos format.
However now I save the output in a temporary file on the windows server and then use xcopy to copy it ot the original file.

I would like to avoid this and edit the file in place. Any suggestions ?

Thanks.
# 6  
Old 01-13-2011
Don't use Notepad!

Download something like WinVi.

In the short-term use the Windows (DOS) edit program, if it's available to you, to open the file, then just save it and quit. Then Notepad should have its newlines.
# 7  
Old 01-13-2011
Thank you - I am trying to get all these steps automated. For now, the pipe works. But I would really like to edit the file in place...

---------- Post updated at 12:00 PM ---------- Previous update was at 11:54 AM ----------

I am seeing a different error now, when I edit the text file on the remote windows server 'in place' using sed (from cygwin shell):

sed: cannot rename ./sedploEpx: Invalid cross-device link

Any ideas ?
Thanks.
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 keep staying on remote server after executing a shell script with if then exit end statement?

i have a "if .. then exit end " in s shell script on remote servers. now the connection to the remote server got killed after i run this script on the remote servers. How do i run this script on remote hosts and still keep remote connections alive after executing the script. Thank you. (10 Replies)
Discussion started by: moonmonk
10 Replies

2. UNIX for Dummies Questions & Answers

Executing ksh script to remote server want output on same window

I'm having a brain freeze moment. I've created a ksh script in AIX that ssh's to a remote server, executes some commands, and then logs out. All of this is sent to a file. I then have the script cat the file so i can see the output. Even though the cat command is outside of the remote session part;... (5 Replies)
Discussion started by: seekryts15
5 Replies

3. UNIX for Dummies Questions & Answers

Executing a script in remote server

Hi All, I have 2 servers A and B. I need to connect to server B from server A and execute a shell script in B which will create some files and i need to copy those files back to server A. Required easiest possible for perfoming above task. (1 Reply)
Discussion started by: Girish19
1 Replies

4. Shell Programming and Scripting

Executing local script/command on remote server

I have a command that I want to run on machine B from machine A. If I run the command on machine B locally, it works fine. Here is the command: for n in `find /data1/ -name 'ini*.ext'` ; do echo cp $n "`dirname $n `/` basename $n .ext`"; done From machine A, I issue this command ... (3 Replies)
Discussion started by: dirtyd0ggy
3 Replies

5. Shell Programming and Scripting

Problem executing perl script on remote server

Hello, I am running in to a problem running a perl script on a remote server. I can run a simple script test.pl which contains just a print statment without issue by running ssh root@1.2.3.4 perl test.pl However, I have a more complex script that does not execute as expected. I think I... (3 Replies)
Discussion started by: colinireland
3 Replies

6. Shell Programming and Scripting

Executing remote server sqlplus

Hello Guys I have to compare flat file record to oracle table record count count which are on different servers I am taking the flat file record count from the server now I am connecting to remote server first and then running sqlplus But after connecting to remote server the sqlplus... (3 Replies)
Discussion started by: Pratik4891
3 Replies

7. Shell Programming and Scripting

executing commands in remote server using ssh

I have some commands which need to be executed in remote machine. I have Linux Server from where I need to connect to Solaris server using ssh and then declare some variable over there and run some commands. I don't want to call a script which is present in Solaris server from Linux server... (7 Replies)
Discussion started by: maitree
7 Replies

8. UNIX for Dummies Questions & Answers

Executing ls command in remote server

Hi Guru, I have a requirement where i need to list the *.csv files in my remote server and copy a file from that server to my unix server I wrote dis code #!/bin/sh . /home/aaa/bb/GlobalHost.sh export HOST export USER export PWD ftp -n $HOST <<END_SCRIPT quote USER $USER quote... (1 Reply)
Discussion started by: pssandeep
1 Replies

9. Shell Programming and Scripting

Executing awk in a remote server using ssh

Hello Everybody, I'm facing a weird problem with the awk command. I'm trying to execute a simple awk command as follows, echo 1 2 | awk '{print $2}' This command prints the output 2. When i try to execute the same command in a remote server using ssh as follows, ssh user@host... (2 Replies)
Discussion started by: karthikv
2 Replies

10. Shell Programming and Scripting

executing a remote location script from local server

hi i am having two servers one is local and remote(FTP)server.from local server i have to connect to remote server and execute a shell script i want to run a shell script(remote location) from my local server i am having some knowledge on ftp but i am not getting the result .please give ... (2 Replies)
Discussion started by: srivsn
2 Replies
Login or Register to Ask a Question