954,176 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to prevent user close window during script execution?

As mentioned in the title.
I wrote a script that has pretty long execution time. Some user just close the window half way and in the end cause some file corrupted. Is there any way to prevent the user closing the window? (Like turn the 'x' button of the window title bar grey color?)

rinque
Newbie Poster
3 posts since Aug 2005
Reputation Points: 10
Solved Threads: 0
 

echo "please do not close this window until promted, this may take awhile"

sorry, I was trying to be funny. I am not sure how to do waht you wnat.

shanenin
Posting Whiz in Training
217 posts since May 2005
Reputation Points: 10
Solved Threads: 17
 

there is no real way to stop a user from closing a window using a shell script.

but if your worring about your shell script being half way through something when they close the window.

use

nohup

this makes the process not honour hang up signals

NOTE: you will no long output stuff to the tty, so if you want user imput its prolly best to do as follows, run a process asking for the imput without nohup then run another process accepting the input from the command line with nohup.


I havent checked this but you may also be able to run a function as nohup, I don't know.

Paul.Esson
Junior Poster
181 posts since Feb 2005
Reputation Points: 21
Solved Threads: 10
 

thanks for your reply!
but how about if the window is launched using 'cmdtool' command from the script itself? can closing this window be prevented? like disable the 'x' button?

rinque
Newbie Poster
3 posts since Aug 2005
Reputation Points: 10
Solved Threads: 0
 

Im not to certain, would depend on your terminal. there might be a way of stopping ppl closing the window in certain terminals.

Paul.Esson
Junior Poster
181 posts since Feb 2005
Reputation Points: 21
Solved Threads: 10
 

Hi I know this post has not been updated for awhile, but I am facing the same exact problem like the original poster! Anyone knows of any update to this question?

hungtat
Newbie Poster
1 post since Oct 2006
Reputation Points: 10
Solved Threads: 0
 
Hi I know this post has not been updated for awhile, but I am facing the same exact problem like the original poster! Anyone knows of any update to this question?

I would still suggest using nohup atleast if the user closes the terminal you will still be processing.

You can use nohup as follows so your users can see the output of your script.

nohup ./test.sh | cat
Paul.Esson
Junior Poster
181 posts since Feb 2005
Reputation Points: 21
Solved Threads: 10
 

If you don't want the user to notice the script running:

nohup script.sh <parameters>  2>&1 > ./logfile &


As long as your script does not ask for user input this will work. Otherwise you will have to resort to nohup and an expect script or nohup and a here document.

jim mcnamara
Junior Poster
180 posts since May 2004
Reputation Points: 62
Solved Threads: 10
 

I had the same issue, but what i did is i just put time and refresh it every minute or so.
this way the user knows something is happening

rashshell
Newbie Poster
1 post since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You