#!/bin/bash
for file in find /devl/bfx/ecif/etl/$ProjectTarget/parameterfiles/ -exec grep -l CNTCT{} \;
do ls -l $file
sed -e 's/CNTCT/CNTCTST/' $file > $file.tmp
mv $file.tmp $file
done
for file in find /devl/bfx/ecif/etl/$ProjectTarget/parameterfiles/ -exec grep -l DBCIBNR{} \;
do ls -l $file
sed 's/DBCIBNR/DBCIBC4/g' $file > $file.tmp
mv $file.tmp $file
done
This script runs but do not replace the string. Can someone tell me what i am missing here. My local system os is linux and remote system is solaris.
Assumptions - ProejctTarget is a directory on the remote node and the shell script has to live on that node to work. Either that or you have to nfs mount your remote directory on let a local copy of dbchange.sh see it as local.
Strongly advise that you copy the script to the remote server and test it thoroughly there from the Solaris command prompt (without the bash shebang unless you have bash on the Solaris box) but with the shebang to match your Solaris account (e.g. /bin/ksh). The script contains numerous syntax errors and fundamental errors and it needs serious debugging. When debugged I would recommend that you execute the remote script from ssh.
As far as I can see the script actually does nothing useful - mainly because the "find" statements never execute. Unless this is a mispaste, the script should be giving syntax errors on the "for" and "do" lines.
My usual comment. With faulty code we need a written description of what the script should do complete with sample input and sample output.
My guess for some corrections (assuming that you run the script on the Solaris box). Totally untested and without warranty and intended as an exercise in correcting Shell syntax:
#!/bin/ksh
#
Project_Target="MYVALUE" # This variable needs a value. Perhaps as $1 ?
#
find /devl/bfx/ecif/etl/"${ProjectTarget}"/parameterfiles/ -exec grep -l "CNTCT" {} \; | while read file
do
ls -l "${file}"
sed -e 's/CNTCT/CNTCTST/g' "${file}" > "${file}.tmp"
mv "${file}.tmp" "${file}"
done
#
find /devl/bfx/ecif/etl/"${ProjectTarget}"/parameterfiles/ -exec grep -l "DBCIBNR" {} \; | while read file
do
ls -l "${file}"
sed -e 's/DBCIBNR/DBCIBC4/g' "${file}" > "${file}.tmp"
mv "${file}.tmp" "${file}"
done
Notice the subtle addition of space characters on the "grep" lines.
Because the script now has the potential to change live parameter files, please test on a test system having backed-up the original files.
A script of this nature should backup the original files before making changes. It's good working practice and it creates an Audit Trail.
1) Bumping up posts or double posting is not permitted in these forums.
2) You say you did mot get desired output, fine, what did you get then?
3) Why are you mixing scripts written in bash and ksh? knowing that linux will not understand by default ksh and solaris bash...
Sorry, but the above sentence makes absolutely no sense in English. Please re-phrase the statement.
Not clear which process takes place on which computer or why you do not copy the script to the remote computer first, then execute that script on the remote computer.
i m trying to find and replace a string on remote server (SOLARIS) from Local server (Linux).
dbchange.sh is the script which gets executed on Solaris server to find and replace "String" it has a variable $ProjectTarget .
I am not suppose to keep script on Remote server.
Some of the files you are copying from Server1 to Server2 appear to be the same files that you wish to edit on Server2.
If ALL the files which need editing exist on Server1 and will be copied to Server2, why not edit them (to temporary names) locally and then copy the edited versions to Server2 ?
Addendum: It would be much easier to run the whole process from Server2.
Thats correct Methyl but server1 is a production server , we should not be editing anything on that server. The ID which is used here doesn't have write access to those files.
I wish this could have been easy.. Can you guide me on how we can do this from remote. Thanks
The Development server only needs read access to the Live server files. I would suggest running the whole process on the Development server and copying the files from the Live server to the Development server and then correcting the parameters.
Hi I am new to UNIX/Linux. Can someone place help me with this question? Write a one line statement to substitute the string on Server1 with Server2 in the config.xml