The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Writing script for finding a string and replacing Aditya_IT Shell Programming and Scripting 4 08-06-2008 12:05 PM
replacing parameter in shell script satgur Shell Programming and Scripting 1 08-02-2008 05:05 PM
Running from Shell Vs running from RC script vickylife SUN Solaris 2 07-31-2008 10:01 AM
Replacing tape drive in RS/6000 7025 F40 running AIX 4.2.1? phaedrus AIX 2 11-12-2007 04:33 PM
replacing contents of files from a bash script HumanBeanDip Shell Programming and Scripting 2 09-13-2002 03:42 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-03-2008
chebarbudo's Avatar
chebarbudo chebarbudo is offline
Registered User
  
 

Join Date: Nov 2008
Location: various
Posts: 188
Question replacing a script while running

Hi there,

How can I run a script being sure that it runs all the way to the end even if the source file is deleted or replaced while running?
Actually, I have a script that runs daily on several servers. It replaces local files by updates from a master server. But I'd like it to replace itself too if an update is found on the master server.

Here is an example of what happens if a script is replaced while running:

Code:
~# cat script
echo statement 1
cp $0.update $0
echo statement 2
~# cat script.update
echo statement 3
cp $0.update $0
echo statement 4
~# bash script
statement 1
statement 4

How can I make sure the script runs entirely even if replaced while running?
1) The replacement file should not run immediately, this update will run the next day.
2) I would prefer not to have to create temporary files.
3) Although it would be a simple solution, it's hard for me to wait until the end of the script to do the replacement because other tasks run after files are updated.

Thanks in advance
Santiago
  #2 (permalink)  
Old 12-03-2008
demwz demwz is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 128
it should be posible to replace a script while it is running withou any problem bcs the file is loaded into memory at execution time
  #3 (permalink)  
Old 12-03-2008
chebarbudo's Avatar
chebarbudo chebarbudo is offline
Registered User
  
 

Join Date: Nov 2008
Location: various
Posts: 188
Although I'm a newbie, I think the following code clearly shows that this is not the case:

Code:
~# cat script
echo statement 1
cp $0.update $0
echo statement 2
~# cat script.update
echo statement 3
cp $0.update $0
echo statement 4
~# bash script
statement 1
statement 4

  #4 (permalink)  
Old 12-07-2008
chebarbudo's Avatar
chebarbudo chebarbudo is offline
Registered User
  
 

Join Date: Nov 2008
Location: various
Posts: 188
Here is a solution that I found,
Tell me if this looks OK.

Code:
~# cat myscript
(( $inside )) || { inside=1; . "$0"; exit; }
echo statement 1
cp $0.update $0
echo statement 2
~# cat myscript.update
(( $inside )) || { inside=1; . "$0"; exit; }
echo statement 3
cp $0.update $0
echo statement 4
~# myscript
statement 1
statement 2
~# myscript
statement 3
statement 4

Closed Thread

Bookmarks

Tags
replace, running, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0