Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SED command in script 1

Status
Not open for further replies.

AnotherAlan

Technical User
Feb 10, 2006
362
GB
Hi all,

I am attempting to insert a line to a start up script across a range of servers.
I have a working command, at least it works from the command line, but I am receiving command garbled messages when attempting to run from within a script. I guess this has to do with the new line requirements...maybe?

The script and command is as follows;
#!/bin/ksh

script=/tmp/test/etc
date=`date +%d-%m-%y`

for h in `cat etc_server`

do
ssh -n $h "cp ${script} ${script}.${date};sed '{
9a\
<two tabs here for formatting only> rm /petc/log/etcprocs
}' < ${script}.${date} > $script"

done


I know there is a uuoc here, but this is only testing..!!!

Can anyone suggest a better / working alternative to this?

All help much appreciated,
Thanks
Alan
 
To confirm,

I should point out that when I issue the sed command from a script without using ssh this works.
So it would appear that my syntax within the ""'s is incorrect.i.e

#!/bin/ksh

script=/test/etc_script

date=`date +%d-%m-%y`

cat $script | sed '{
9a\
rm /petc/log/etcprocs
}' > $script.$date

This works...but the same command within an ssh command fails.

Thanks
 
Me again,

I have figured out a workaround to this, for those interested.
I am going to copy my working script to each host and run it from there. This works for me, however, it would be interesting to know why it wouldn't behave when entered as part of the ssh command list.

Alan
 
If you escape the \, i.e. use \\, it should work.

The problem is that the shell evaluates the part between the " quotes before passing it to the ssh command as a parameter, and at that point it strips out the \. Escaping it means that it will strip out only one slash, i.e. says you really really want a slash there.

Annihilannic.
 
Anni,

Works like a dream. Thanks for your help, it is much appreciated.

Alan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top