Regarding a query on making changes to a running script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Regarding a query on making changes to a running script
# 1  
Old 05-08-2015
Regarding a query on making changes to a running script

Hello All,

Greetings !!

I have a query here to all is as follows:

Question: Let's say we are running a script in a UNIX box and we have opened an another session and then made changes in script of some statements NOT to be print some values(just an example) so when I am monitoring the other session changes didn't reflect, so my question is after running a script:

i- Seems script will be loaded to RAM(MEMORY of UNIX) from where it is picking the script?
ii- So after script's completion only changes will be picked which we made after running the script?
iii- Is there any way if above 2 points are valid like we can make changes while a script is running and can be shown within same run of UNIX script?

Will be grateful to you, if someone can put some light on this, I am sorry if this is a basic/dummy question but I faced this, so thought to share with all and get people's view/comments on same.


Thanks,
R. Singh
# 2  
Old 05-08-2015
Changing any program while it is running (C, C++, FORTRAN, ... a.out), awk script, or shell script) might have absolutely no effect (the program was loaded when it started and runs from memory independent of the contents of the file(s) it was loaded from), or might cause it to die a horrible death when a block of memory containing commands being processed changes into something else that might be a mix of characters that don't quite make up the new program or the old program. Specifying when something will continue working unchanged may vary depending on the OS, the shell, the filesystem type from which the program is loaded, whether it is a statically linked binary, a dynamically linked binary, or an interpreted language, whether or not the sticky bits that way), and lots of other conditions.

If you have a separate script that you invoke when you want to produce output after lengthy computational loops in a script, and you change that separate script while the base script is performing one of those lengthy computations; you might get what you want. If you try to change the text of a function that has already been loaded by the shell, later invocations of that function aren't likely to be affected by changes to the source for that function. But if modifying that function at the start of your shell script changes the length of the script and your script consumes more than one block on disk, your script could die when it loads the next block of the script and finds that the command that crossed the boundary between two disk blocks duplicated or dropped a few characters, all bets are off.

Although you might be able to figure out what will happen to you on a particular version of an OS and shell combination, there is no guarantee that the same thing will happen after you upgrade to the next update of that OS or shell.
# 3  
Old 05-08-2015
Mostly you might want to input/output something from the script. I don't suppose you want to change the logic of your script during run-time. You could use a file to read/write data and allow the script to pick up values from the file.
This User Gave Thanks to balajesuri For This Post:
# 4  
Old 05-08-2015
A long script does not read everything in advance.
Then unpredictable things happen when it continues reading the suddenly changed script.
I suggest to create a new script first, then use mv to replace the old script. Running scripts will continue to read from the old script. This should also work with NFS (where the removed script is renamed .nfsXXXXXX) .
# 5  
Old 05-08-2015
What is the definition of a long script?
Me have a (still not working) build script for ffmpeg, beeing a medium (compared to most of my scripts that are scripts and not just command as 'tui-XY') length script of aprox 700 lines.

But then there is VHS, which will become the (my) largest one with 3400 lines once the ffmpeg-build script works and is included. (currently ~2700 lines).
Is that a long script already?

I know (from this forum) of people having scripts with like 20k or even 30k lines.
For those script i'd choose the suggestion of MIG, but for other reasons, as the larger the script, the higher the chance a typo can break everything.
# 6  
Old 05-08-2015
The definition of a long script in this context is a file that contains more bytes than the shell reads in a single read() system call when reading your script. That number can vary from shell to shell (where an update to a given shell counts as another shell) and may vary with the block size of the filesystem from which the script is being read. For most shells I've seen it is somewhere between 512 bytes and 20kb (but I haven't looked at any shell source for several years).
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Making sure only one instance of a script is running

so i have a script that takes a while to complete and its cpu intensive. this script is being used by several users. i want to make sure only 1 user can run this script at any given time. i originally thought of running a while loop to egrep the process table of the PID ($$) of the process,... (7 Replies)
Discussion started by: SkySmart
7 Replies

2. UNIX for Dummies Questions & Answers

Extract only the data from ksh script running netezza query

Hi I searched this forum before posting the question, but couldnt find it, the issue i'm facing is, i'm trying to select a column from a netezza table from a korn shell script, but the query runs var=$(nzodbcsql -q "select MAX(millcount) from table1";) echo $var it returns the value like... (10 Replies)
Discussion started by: maximus_jack
10 Replies

3. Shell Programming and Scripting

Error in running DB query by script

Hi I was trying to fetch data from database. But the number of rows exported were huge so i got the error. Experts please advice. Thanks a lot for your supprt. #: ./script.sh ./script.sh: xmalloc: subst.c:3076: cannot allocate 1401346369 bytes (0 bytes allocated) (2 Replies)
Discussion started by: brij123
2 Replies

4. Shell Programming and Scripting

Running sed from a script query

Hello! I'm trying to run this code to print the body of an html document (all text in between <body> and </body>) from a script but am unsure how to call it from the command line interface. /<body>/,/<\/body>/ 1s/.*<body>// $s/<\/body>.*//p I have tried to call it using this: sed... (6 Replies)
Discussion started by: bgnersoon2be#1
6 Replies

5. Shell Programming and Scripting

Making use of multiple cores for running sed and awk scripts

Hi All, After reading that the sort command in Linux can be made to use many processor cores just by using a simple script which I found on the internet, I was wondering if I can use similar techniques for programs like the awk and sed? #!/bin/bash # Usage: psort filename <chunksize>... (7 Replies)
Discussion started by: shoaibjameel123
7 Replies

6. Shell Programming and Scripting

Query on decision making...

is_number() { echo $1|egrep '^*$' 2>&1 1>/dev/null return $? }why the following snippet always give an output as "no" and never "yes" whatever the parameter I give to function is_number? if ]; then echo yes; else echo no; fi In addition, the function is_number() is... (5 Replies)
Discussion started by: biglau
5 Replies

7. AIX

Query on running script with nohup

Hi, I'm trying to run database restore script with the nohup command as it will run for long hours since if I run it normally, the putty session will become inactive and the restore gets terminated. The command I use is nohup db2 -tvf FBR_NODE0000.scr -z FBR_NODE0000.log & But the problem is... (2 Replies)
Discussion started by: vkcool.17
2 Replies

8. Shell Programming and Scripting

Query Oracle tables and return values to shell script that calls the query

Hi, I have a requirement as below which needs to be done viz UNIX shell script (1) I have to connect to an Oracle database (2) Exexute "SELECT field_status from table 1" query on one of the tables. (3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies

9. Shell Programming and Scripting

Running script from script query

Hi I have a question Suppose i have three scripts & i have created a top level script to run these. eg. leaf1.csh leaf2.csh leaf3.csh top.csh Now in top.csh i have written #!/bin/csh leaf1.csh leaf2.csh leaf3.csh Now my question is when i run this top level script when it... (1 Reply)
Discussion started by: sarbjit
1 Replies

10. Shell Programming and Scripting

error ORA-06512 while running query in script

1 #!/bin/ksh 2 ################################################################ 3 # Written by Johnson 12/03/2008 4 # Version 1.0 5 # This script executes some SQL to provide Spike Check Report to TNS team. 6 ... (3 Replies)
Discussion started by: shivanete
3 Replies
Login or Register to Ask a Question