Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Ed to modify a file --- or not?

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-19-2017
edstevens edstevens is offline
Registered User
 
Join Date: Oct 2011
Last Activity: 21 August 2017, 7:48 AM EDT
Posts: 82
Thanks: 18
Thanked 12 Times in 12 Posts
Ed to modify a file --- or not?

Running Oracle Linux 6 (derivative of RHEL 6)

Given this snippet of code in a shell script:


Code:
#-- reset oratab to use 11.2 home for dwdev
#--  normally we'd just use sed to do this sort of thing, but that would
#--  require permissions that we don't have in the /etc/ directory, so we
#--  use 'ed' instead.
echo =======================================================
echo `date +%Y-%m-%d" "%H:%M:%S` - Modifying /etc/oratab
echo Original oratab entry for dwdev:
grep ^dwdev /etc/oratab
ed -s /etc/oratab <<EOF
,s|dwdev:/u01/app/oracle/product/12.1.0.2/dbhome_1:N|dwdev:/u01/app/oracle/product/11.2.0.4/dbhome_1:N|
w
q
EOF
echo New oratab entry for dwdev:
grep ^dwdev /etc/oratab

The output looks exactly as I expect, and the rest of the script, that is depending on these settings, behaves exactly as planned. Here's the output through that section:

Code:
2017-05-19 12:51:28 - Modifying /etc/oratab
Original oratab entry for dwdev:
dwdev:/u01/app/oracle/product/12.1.0.2/dbhome_1:N# line added by Agent
New oratab entry for dwdev:
dwdev:/u01/app/oracle/product/11.2.0.4/dbhome_1:N# line added by Agent

However, when the script is complete, I go back and check the contents of the subject file (/etc/oratab) and it is back to its original:


Code:
oracle:dwdev$ grep ^dwdev /etc/oratab
dwdev:/u01/app/oracle/product/12.1.0.2/dbhome_1:N               # line added by Agent

The rest of the script is pretty lengthy and involved, but I see nothing else in it that could conceivably modify the file /etc/oratab
Sponsored Links
    #2  
Old 05-19-2017
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 18 October 2017, 5:21 AM EDT
Location: San Jose, CA, USA
Posts: 10,536
Thanks: 548
Thanked 3,689 Times in 3,147 Posts
From the output you have shown us, it appears that ed is doing what you requested. So, if the contents of /etc/oratab have gone back to their original state when the script terminates, it would seem likely that has modified the file.

If the command:

Code:
grep oratab scriptname

where scriptame is the name of the file containing your shell script doesn't show any output other than:

Code:
echo `date +%Y-%m-%d" "%H:%M:%S` - Modifying /etc/oratab
echo Original oratab entry for dwdev:
grep ^dwdev /etc/oratab
ed -s /etc/oratab <<EOF
echo New oratab entry for dwdev:
grep ^dwdev /etc/oratab

then one might guess that:
  1. something in your script invokes another command that resets /etc/oratab's contents,
  2. there is another directory entry hard-linked to /etc/oratab and your script is modifying the file using a different filename,
  3. there is another file that is a symbolic link pointing to /etc/oratab and your script is modifying the file using the name of one of those symbolic links, or
  4. some other script is asynchronously changing the contents of /etc/oratab that seems to run consistently between the time the second grep in your code shows that the file changed and the time when you notice that the contents have reverted to their original contents after your script terminates.
The Following User Says Thank You to Don Cragun For This Useful Post:
edstevens (05-23-2017)
Sponsored Links
    #3  
Old 05-22-2017
edstevens edstevens is offline
Registered User
 
Join Date: Oct 2011
Last Activity: 21 August 2017, 7:48 AM EDT
Posts: 82
Thanks: 18
Thanked 12 Times in 12 Posts
Don - thanks for the reply. Except for the idea of the links, that what I would have thought. Since this is a vm I build myself, I know there are no links involved, nothing else in the script to modify the file, and no other scripts running. In cutting down the script for a 'proof demo' with lots of debugging 'echo' messages, I do find that the change happens during/after invoking sqlplus to shut down the database. At that point, probably best if I take the issue to an Oracle forum. I'll post back here what I find out, to give closure to the thread.
The Following User Says Thank You to edstevens For This Useful Post:
Don Cragun (05-22-2017)
    #4  
Old 05-23-2017
edstevens edstevens is offline
Registered User
 
Join Date: Oct 2011
Last Activity: 21 August 2017, 7:48 AM EDT
Posts: 82
Thanks: 18
Thanked 12 Times in 12 Posts
Confirmed, issue is a background task involved with Oracle Grid Infrastructure.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
File modify honey26 Shell Programming and Scripting 7 06-06-2015 06:32 AM
Modify a file by another file: add new line and variable after string is found bipbip Shell Programming and Scripting 3 05-07-2012 02:56 AM
Modify file kylle345 Shell Programming and Scripting 3 07-02-2011 03:07 AM
Modify a file ./hari.sh Shell Programming and Scripting 5 10-02-2008 07:03 AM
Can I modify the .bashrc file instead of .profile file to customize my login? Hyunkel Shell Programming and Scripting 1 09-25-2007 08:37 PM



All times are GMT -4. The time now is 09:07 AM.