How to update script by itself?
Hi all,
Is there a way to update one script by itself from another location? Say once run /root/Desktop/test.sh, I can copy /tmp/test.sh to replace it. I know that it should work if I use one separate update script like up.sh to do this work. But any possible update the script itself once run it? It shall be OK the test.sh script stops after run. And I get a new test.sh so that I just re-run the script. This is a process to update one test program trigerred by a script. From the script, I can tell whether there is any updating and do updating accordingly. Thanks a lot in advance, sscn |
I think SVN tool can be used to update such script as it is used to maintain configuration files and same can be used to maintain script files as well.
|
I think your proposed scheme should work on Linux file systems (but not Windows' NTFS) because of the way they work. This assumes you use mv or a similar command to replace the executing script, not an edit command.
If an executing script is replaced, the old version isn't really deleted. Rather, the directory node that points to it is just changed to point to the new version while the old version continues to execute. Once execution completes, the file is closed and the file system sees there are no links to the old version so it's deleted. However, I think it would be much better and safer to not actually replace a script but to modify a parameter file, maybe ~/.config/mystuff.conf or similar. Then have your script read the config file. There are lots of examples of this kind of configuration file in /etc/sysconfig/. |
Quote:
Even if you're sure there are no possible other users, there's a very remote chance that some cron job could accidentally do the same thing. |
Where to put user program and logs?
Hi KenJackson,
I worked one way to update my script itself automatically. 1. Script itself can tell if there is any difference against another same name script by md5sum; 2. If there is any difference, script can call another script to run in background and exit; 3. The background copy script will sleep 3 seconds and then recover the target script automatically. Another question is that where I can put my program if /tmp folder is not good for user test program and logs. Thx, sscn |
All times are GMT -5. The time now is 08:06 PM. |