cp & sed error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cp & sed error
# 8  
Old 02-06-2006
Did you have the write permission to the directory you are trying to write?
# 9  
Old 02-06-2006
Yes, for sure.
# 10  
Old 02-06-2006
Quote:
Originally Posted by n8575
by the way, why use ls -l in the for loop, instead of just ls?
ls -1 != ls -l
You are not accurately trying the suggestions that you are being given.

Put two lines before your for loop
echo src = $src
echo dest = $dest

And change your sed statement to something like:
echo "s#${src}#${dest}#g"
so we can see what command is being generated. Post both the code you use and the output it generates.
# 11  
Old 02-07-2006
Yes, that was a typo....i did use ls -1, not ls -l (it's become natural to type it coz i use it so often!) and got the errors mentioned earlier.

Anyway, i tried it again. Here is my code...

for i in `ls -1 $ORACLE_BASE/admin/${dest}/pfile/`
do
echo src=${src}
echo dest=${dest}
echo "replacing ${src} to ${dest} for $i"
#cp "$i" "$ORACLE_BASE/admin/${dest}/pfile/$i_backup"
echo "s#${src}#${dest}#g"
sed -e "s#${src}#${dest}#g" "$i"
#rm -f "$i_backup"
done
echo "finished"

And here is the output....

src=db1
dest=db2
replacing db1 to db2 for init.ora.162006131752
s#db1#db2#g
Can't open init.ora.162006131752
finished
# 12  
Old 02-07-2006
I can only see one possibility why your script fails. You are looking for your file in the wrong place.


Code:
for i in `ls -1 $ORACLE_BASE/admin/${dest}/pfile/`
do

# i = init.ora.162006131752 
# the qualified path is 
# $ORACLE_BASE/admin/${dest}/pfile/init.ora.162006131752

echo src=${src}
echo dest=${dest}
echo "replacing ${src} to ${dest} for $i"

#cp "$ORACLE_BASE/admin/${dest}/pfile/$i" "$ORACLE_BASE/admin/${dest}/pfile/$i_backup"
echo "s#${src}#${dest}#g" 
sed -e "s#${src}#${dest}#g" "$ORACLE_BASE/admin/${dest}/pfile/$i"
#rm -f "$i_backup"
done
echo "finished"

# 13  
Old 02-07-2006
I have done exactly what u showed below, and when the script is running i see that that does work. Only thing is that it doesnt get saved, so when i open the file after the script has finished, it's with the ${src} words.

I tried this, but it didnt work...

sed -e "s#${src}#${dest}#g" "$ORACLE_BASE/admin/${dest}/pfile/$i" > $ORACLE_BASE/admin/${dest}/pfile/$i

I also tried this...

sed -e "s#${src}#${dest}#g" "$ORACLE_BASE/admin/${dest}/pfile/$i" >> $ORACLE_BASE/admin/${dest}/pfile/$i

...but it just added the 2 files together (the one with ${src} words and the one after sed does it's job). I only want the part with the ${dest} words saved in this directory. how can i do this without using cp, coz that always seems to be giving errors.
# 14  
Old 02-07-2006
Quote:
Originally Posted by n8575
sed -e "s#${src}#${dest}#g" "$ORACLE_BASE/admin/${dest}/pfile/$i" > $ORACLE_BASE/admin/${dest}/pfile/$i
sed -e "s#${src}#${dest}#g" "$ORACLE_BASE/admin/${dest}/pfile/$i" >> $ORACLE_BASE/admin/${dest}/pfile/$i
They will never work. You are reading and writing data back to it at the same time.

Code:
sed -e "s#${src}#${dest}#g" "$ORACLE_BASE/admin/${dest}/pfile/$i" >> "$ORACLE_BASE/admin/${dest}/pfile/$i_backup"

mv "$ORACLE_BASE/admin/${dest}/pfile/$i_backup" "$ORACLE_BASE/admin/${dest}/pfile/$i"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Echo "abc" | sed - r 's/a/&_&/

I want to know the working of & here step by step using sed command. (1 Reply)
Discussion started by: Preeti07
1 Replies

2. Shell Programming and Scripting

Need Script to ZIP/SAVE & then DELETE Log file & send a mail conformation for any error

ENVIROMENT Linux: RHEL 6.4 Log Path: /usr/iplanet/servers/https-company/logs Log Format: user.log.03-15-2015 I have log4j log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I need a script that will run daily that... (1 Reply)
Discussion started by: admin_job_admin
1 Replies

3. Shell Programming and Scripting

if statement with '&&' gives error

Hi, I'm using the && operator in if statement: if ; then exp $UID/$PWD@$ORACLE_SID FILE=./DUMP/$TODAY$CONCAT_STR$USERNAME.dmp STATISTICS=NONE LOG=./LOG/$TODAY$CONCAT_STR$USERNAME.log elif ; then expdp $UID/$PWD@$ORACLE_SID DIRECTORY=./DUMP/ DUMPFILE=$TODAY$CONCAT_STR$USERNAME.dmp... (8 Replies)
Discussion started by: priya001
8 Replies

4. Shell Programming and Scripting

Help with sed ( & )

I am searching for a specific pattern and replacing with ( ) for matched pattern .I am not getting the expected result ..... Here is the file cat test cool change Frinto Francis Frinto cool change Attitude /usr/bin sed 's/*/( & )/' test ( cool ) ( change ) ( )Frinto Francis... (2 Replies)
Discussion started by: frintocf
2 Replies

5. Shell Programming and Scripting

Perl & Sed command -- Out of Memory Error

Experts, We used to receive our source files with '~^' as row delimiter. This file contains 2500K records and two of the columns having value in HTML formats within the file. While running the below commands against the file, we are encountering out of memory, could you please help to... (3 Replies)
Discussion started by: srivijay81
3 Replies

6. Shell Programming and Scripting

sed & areas respectively sed & pyramiding

Hello everyone, i wonder if someone could give me an advice regarding the following problem using sed. Given ist a structure as shown below: <aaa>text1<b>text2</b>text3<c>text4</c>text5</aaa> Now I want to change the outer tag from "aaa" to "new" and replace all tags inside the outer tags... (4 Replies)
Discussion started by: Donaldinho
4 Replies

7. UNIX for Dummies Questions & Answers

Question: Help need to remove blank line & sed: Couldn't re-allocate memory error.

I've shell script where i used the below command to take the line which contains patterns. sed -n "/$year 05:/,/$year 17:/p" trace.log | grep -f patterns.txt > output.log This was working fine for long time, but now a days this script is not working with and throwing error like sed:... (8 Replies)
Discussion started by: senthil.ak
8 Replies

8. Shell Programming and Scripting

Help, | ! & [ ^ in sed

Hi,everyone: I'm new to shell, and I'm confued with some script: ssum=`echo "$lsum" | sed 's|!|\\\\!|g'` line1=`echo "$line" | sed 's!\!\\\]!g'` line3=`echo "$line2" | sed 's!\&!\\\&!g'` sed "s^${line3}^${newline3}^g" ${TIER4FILE} > ${TMP_TIER4FILE} In the first three lines,... (5 Replies)
Discussion started by: mycoy
5 Replies

9. Linux

Kernal panic error& setuproot:error mounting /proc&/sys

Hi all, I am new to redhat/fedora linux. In fedora linux 6,we created one file system(hda3 - /fs). in this mount poing we were installed mounta vista os. while booting we are getting below error messages. 1) Booting 'mountaVisat(2.6.18_pro 500_pc_target-x86_586 smp)' root(hd0,1)... (2 Replies)
Discussion started by: arjunreddy3
2 Replies

10. Shell Programming and Scripting

sed & awk

Hi. I'm going to learn scripting and i have the following topics on the list: sed, awk, shell scripting, perl. My question is, whehter i should learn sed and awk? Aren't this tools outdated? Although i see that GNU upgrade it's versions of these tools from time to time. And, the next... (9 Replies)
Discussion started by: kukuruku
9 Replies
Login or Register to Ask a Question