LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-24-2011, 06:07 AM   #1
sscn
LQ Newbie
 
Registered: Jan 2006
Location: China
Distribution: Fedora
Posts: 27

Rep: Reputation: 0
Cool 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
 
Old 11-24-2011, 06:18 AM   #2
mukt-kalandar
LQ Newbie
 
Registered: Feb 2011
Posts: 7

Rep: Reputation: 0
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.
 
Old 11-24-2011, 09:00 AM   #3
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora, PCLinuxOS
Posts: 590

Rep: Reputation: 73
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/.
 
Old 11-24-2011, 09:12 AM   #4
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora, PCLinuxOS
Posts: 590

Rep: Reputation: 73
Quote:
Originally Posted by sscn View Post
Say once run /root/Desktop/test.sh, I can copy /tmp/test.sh to replace it.
On a security note, copying a script from /tmp/ for root to execute would be a bad idea in a multi-user environment. It may provide an opportunity for someone to modify or replace the file, maybe even accidentally, and get their substitute executed by root.

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.
 
Old 12-28-2011, 01:42 PM   #5
sscn
LQ Newbie
 
Registered: Jan 2006
Location: China
Distribution: Fedora
Posts: 27

Original Poster
Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Adding start up script in rcX.d --> Via update-rc SCRIPT defaults .... :-( jv2112 Linux - Newbie 6 07-04-2011 07:19 AM
Shell Script: want to insert values in database when update script runs ring Programming 2 10-25-2007 11:48 PM
update script... isimigorecem Linux - Networking 4 02-27-2006 10:59 PM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 06:32 PM
Update Script justin_p Slackware 2 06-06-2005 11:56 AM


All times are GMT -5. The time now is 06:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration