1

I know that editing the file on disk where a script is stored while this script is running is a very bad idea.

But will it hurt if I make a soft link (ln -s) to some version of the script, then run it by typing that symlink name and, while it is still running, change the link to point to another version of the same script? What the running script is connected to, the very inode where the script is stored or the whatever-is-found-by-following-the-symlink?

By the way, how are things with sourcing scripts inside other scripts? The sourced script is wholly read and executed, isn't it?

The question is primarily about bash scripting.

Thanks to everybody in advance!

Esmu Igors
  • 239
  • 3
  • 6
  • you can test and try such things - but if you do - something is wrong with design of your solution - you could start with question how to redesign your solution :D – Drako Apr 25 '18 at 13:00
  • OK, the thing is that I have a directory of scripts on NFS disk on computational cluster. Usually some 20 calculations are running on different nodes; previously I was running them by typing the whole name of the script (containing version no.), but this became quite impeding with the growth of scripts with different versions. Then I resorted to make the symlink to be able to launch calculations by typing just the common name of the script. Now I wonder if that's OK. – Esmu Igors Apr 25 '18 at 13:35
  • One thing I now remember is that _top_ shows the process name as the name of symlink and not the name of its target. Is this the answer to my question or just some peculiarity of _top_ or something else? – Esmu Igors Apr 25 '18 at 13:37
  • 1
    Sounds like a complex environment and difficult to suggest something immediately. you could have working bucket of scripts - create lock file when run and delete when stop any separate file and have separate script repo in which update them and some rsync with condition to update only if no lock file. (but works only if those scripts ever stop, otherwise need maintenance window or hack that you are actually looking for :D – Drako Apr 25 '18 at 13:45
  • In Linux you can delete (== rename) any file that is open and it won't make any difference to any program that has the file open. That program will be able to continue reading and even writing to the file as if nothing had happened. Reopening won't work however. – sneep Apr 25 '18 at 14:16
  • 1
    @sneep: when using files as objects – I agree, but when launching them as programs (subjects)? how about this: https://stackoverflow.com/questions/3398258/edit-shell-script-while-its-running – Esmu Igors Apr 25 '18 at 14:36
  • Hah. I stand corrected (about bash). :p Oh you edited your post. This is bash/perhaps other *sh-specific behavior. In that case I strongly recommend against fiddling with shell scripts that are being executed. – sneep Apr 25 '18 at 14:39
  • @Drako: thanks for suggestion! I think it would be better to add the following things to ~/.bashrc: 1) check which scripts (versions) are running; 2) move the rest to archive subdirectory; 3) print available version numbers – then it will be relatively easy to select the proper name each time. – Esmu Igors Apr 25 '18 at 14:40

0 Answers0