Overwrite a running shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Overwrite a running shell script
# 1  
Old 02-18-2010
Overwrite a running shell script

Hello all,

This might be a dumb question...but i am running into this situation.

I have a shell script that is currently in running state. It has big sql's in it and will run for few days. What happens if I change the shell now?

Eg: a.shl is running and i want to mv b.shl a.shl

I have tested this and I am getting the results of a.shl (fyi-->b.shl has different content compared to a.shl)
# 2  
Old 02-18-2010
Once it got started execution, moving or editing wont do anything.

The script you had originally will only get executed, if you have to change, you have to kill that process, and start the new again.
# 3  
Old 02-18-2010
A simple way to find out is try out on some other shell script. Write a shell script that does nothing but sleep for a few seconds. (sleep 10). While it is being excuted in a terminal, from another terminal, delete/rename it.
# 4  
Old 02-18-2010
Thanks for your inputs. As long as it takes the original script I am fine.
# 5  
Old 02-18-2010
Quote:
Originally Posted by thegeek
Once it got started execution, moving or editing wont do anything.
Don't think you can count on that. Whether or not the shell keeps a local copy in memory is shell-specific, I've caused long-running BASH scripts to bomb out with syntax errors by modifying them while in execution. Strangely, deleting it may be safer than that -- if the shell already has a handle to the file, that handle will remain valid! The file will only truly be freed from disk once it's closed for the last time.

If you need to derive one script from another, make a copy, don't rip the floor out from under something else.

Last edited by Corona688; 02-18-2010 at 10:46 AM..
# 6  
Old 02-18-2010
I agree with Corona688. Overwriting a script while it is running can cause the script to fail and/or to execute commands out of context.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cp not working in shell script but running perfectly from shell

Dear All, I have script. Dest="" IFS=' ' for translation in $(echo $MY_MAP) do t1=$(echo $translation | cut -d"=" -f1) t2=$(echo $translation | cut -d"=" -f2| cut -d"," -f1) if then Dest=$UNX/$u_product_path/$u_study_path/$UNXTR/$t2 break; ... (4 Replies)
Discussion started by: yadavricky
4 Replies

2. Shell Programming and Scripting

Running 3 shell script parallel in another shell script

Hi, I'm trying to do teh below thing. I have a single script which uses 3 different parameters to do 3 different work like belwo. test1.sh par1 -- it shuts down an instance test1.sh par2 -- it shuts down an instance test1.sh par3 -- it shuts down an instance Now I created a script... (7 Replies)
Discussion started by: bhaski2012
7 Replies

3. Shell Programming and Scripting

Changing shell from a script and running something from the new shell

Hi We use "tcsh" shell . We do the following steps manually: > exec ssh-agent zsh > python "heloo.py" (in the zsh shell) I am trying to do the steps above from a shell script This is what I have so far echo "Executing " exec ssh-agent zsh python "hello.py" exit 0 Problem is... (5 Replies)
Discussion started by: heman82
5 Replies

4. Shell Programming and Scripting

Shell Script for continuously checking status of a another script running in background, and immedia

Hi, I want to write a script which continuously checking status of a script running in background by nohup command. And if same script is not running then immediately start the script...please help.. i am using below command to run script nohup system_traps.sh & but in some... (9 Replies)
Discussion started by: ketanraut
9 Replies

5. Shell Programming and Scripting

Shell script to overwrite a file

Hi Guys, My requirement as follows, i want to write a shell script to display the files of a folder, i export it to a file to mail the file. The problem is the exported file is getting appended every time I run the script. I just want the file to be over written. can anyone suggest?? ... (4 Replies)
Discussion started by: Karthick N
4 Replies

6. Shell Programming and Scripting

Need to overwrite shell script using vi editor

I have an existing shell script that I am trying to modify. I have about 10 lines of info I want to overwrite using text someone emailed to me. I guess what I am trying to do basically is like a copy/paste, but it's not working for me. I am using Cygwin and vi editor. I open the script and... (4 Replies)
Discussion started by: kimberlyg2007
4 Replies

7. Shell Programming and Scripting

Bash shell script to check if script itself is running

hi guys we've had nagios spewing false alarm (for the umpteenth time) and finally the customer had enough so they're starting to question nagios. we had the check interval increased from 5 minutes to 2 minutes, but that's just temporary solution. I'm thinking of implementing a script on the... (8 Replies)
Discussion started by: hedkandi
8 Replies

8. Shell Programming and Scripting

Shell script running command in different shell

Hi All, Is there any way where we can run few commands with different shell in a shell script ? Let's have an example below, My first line in script reads below, #!/bin/sh However due to some limitation of "/bin/sh" shell I wanted to use "/bin/bash" while executing few... (9 Replies)
Discussion started by: gr8_usk
9 Replies

9. UNIX Desktop Questions & Answers

shell overwrite lines in a file

Hello, I have an external file (file.txt). This shall be a kind of a config file for my shell script. I get the line numbers as to a corresponding entry by grep. Now I would like to substitute the corresponding line from the shell script back to the file and exactly on the same line number. ... (4 Replies)
Discussion started by: ACTGADE
4 Replies

10. Solaris

Running from Shell Vs running from RC script

Hi, i have a script which need to do behave differently when run as a startup process from init.d/ rc2.d script and when run manually from shell. How do i distinguish whether my script is run by init process or by shell?? Will the command /proc/$$/psinfo | grep "myscript" work well???... (2 Replies)
Discussion started by: vickylife
2 Replies
Login or Register to Ask a Question