LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Solaris / OpenSolaris (http://www.linuxquestions.org/questions/solaris-opensolaris-20/)
-   -   Couple Bash Scripting Questions (http://www.linuxquestions.org/questions/solaris-opensolaris-20/couple-bash-scripting-questions-4175430685/)

ruberked 10-05-2012 09:44 AM

Couple Bash Scripting Questions
 
New to the site so I hope this is the right forum...wasn't sure if I should ask this in the programming one or not?

I'm working in Solaris 9/CDE. I wrote a simple bash script that kicks off a virus scan in an xterm window and echos out some stuff....but wanted to add a couple things and for life of can't find any info on the following

A. Is there a way to make that particular window un-closeable until script is finished?


B. Is there a way kick off another script/command on the close action if the user closes the current window?


C. is there a way to restore the xterm or bring it to front after the scan is complete?

Any help would be greatly appreciated....thanks in advance! :)

porphyry5 10-05-2012 11:55 AM

Quote:

Originally Posted by ruberked (Post 4798079)
New to the site so I hope this is the right forum...wasn't sure if I should ask this in the programming one or not?

I'm working in Solaris 9/CDE. I wrote a simple bash script that kicks off a virus scan in an xterm window and echos out some stuff....but wanted to add a couple things and for life of can't find any info on the following

A. Is there a way to make that particular window un-closeable until script is finished?


B. Is there a way kick off another script/command on the close action if the user closes the current window?


C. is there a way to restore the xterm or bring it to front after the scan is complete?

Any help would be greatly appreciated....thanks in advance! :)

A. xterm -hold ... -e "/path/to/yourscript.sh" & ... are other options, which must precede -e
B. the xterm referenced by A., or any window the user happens to be currently viewing?
C. fg 'its job number', see man jobs
Job number is number in square brackets, PID is other number listed by bash when background process created, e.g.
Code:

~/Documents $ xterm -hold -name qwerty &
[1] 1590


ruberked 10-05-2012 12:32 PM

Quote:

Originally Posted by porphyry5 (Post 4798179)
A. xterm -hold ... -e "/path/to/yourscript.sh" & ... are other options, which must precede -e
B. the xterm referenced by A., or any window the user happens to be currently viewing?
C. fg 'its job number', see man jobs
Job number is number in square brackets, PID is other number listed by bash when background process created, e.g.
Code:

~/Documents $ xterm -hold -name qwerty &
[1] 1590


Really appreciate it...I'll check out those suggestions!

I guess to answer your question B. (sorry if this makes no sense)....B. would be an alternative to A....

Say for instance....I fire off the scan and echo some stuff to the xterm and a user closes the window for whatever reason....On that close action, I'd like to kick off another script that would continue to monitor scan and what not....

Does that even remotely make any sense? :p

Shoot...I'm probably taking away the point of creating simple bash scripts and should probably just buck up and learn tcl/tk! ;)

porphyry5 10-05-2012 01:09 PM

Quote:

Originally Posted by ruberked (Post 4798209)
Really appreciate it...I'll check out those suggestions!

I guess to answer your question B. (sorry if this makes no sense)....B. would be an alternative to A....

Say for instance....I fire off the scan and echo some stuff to the xterm and a user closes the window for whatever reason....On that close action, I'd like to kick off another script that would continue to monitor scan and what not....

Does that even remotely make any sense? :p

I may have been misunderstanding you. I think what you want to do is manipulate windows through the X system. Check out in particular xdotool, also xwininfo, xsel and wmctrl
xdotool gives you as much control over X windows as a scripting system like AHK does over microsoft windows guis, but its usage is obscure.
wmctrl is more limited, but its use is straightforward
xsel lets you pass things between apps via the various clipboards
xwininfo provides info about particular windows to help identify them to xdotool. There is another app, wininfo, which provides very similar, but somewhat different info to xwininfo

That should keep you busy for a while ;-)

wmctrl will probably do everything you've mentioned here, it can test that a window exists, activate and deactivate, shut them down etc. Its easy to use because it will do these things by window name, but you do have to ensure that any names are unique.

ruberked 10-05-2012 01:20 PM

Quote:

Originally Posted by porphyry5 (Post 4798231)
I may have been misunderstanding you. I think what you want to do is manipulate windows through the X system. Check out in particular xdotool, also xwininfo, xsel and wmctrl
xdotool gives you as much control over X windows as a scripting system like AHK does over microsoft windows guis, but its usage is obscure.
wmctrl is more limited, but its use is straightforward
xsel lets you pass things between apps via the various clipboards
xwininfo provides info about particular windows to help identify them to xdotool. There is another app, wininfo, which provides very similar, but somewhat different info to xwininfo

That should keep you busy for a while ;-)

Ha, yeah that should keep me busy for a while! I've stumble across xdotool in some recent google'n but haven't checked it out....My main problem is it's a classified system so I'm trying to work with what I got so all the IA jerks won't get on my back about installing new software.

Thanks again for the help! Couple different directions I can go so hopefully I slap something real trivial together out of all this..

shivaa 10-12-2012 01:59 PM

I think you should read about the NOHUP signal. Use nohup at starting of the command in your xterm, so command can keep going on until it gets finished, even after you accidently close the xterm.
See here: http://en.wikipedia.org/wiki/Nohup
Second, a closed xterm cannot be recovered or re-opened. The commands or operations that were running in it may get aborted or become defunct. Thus it's better to run important commands with nohup in xterm, so that can still generate output if xterm closes.

ruberked 10-12-2012 04:51 PM

Quote:

Originally Posted by meninvenus (Post 4804177)
I think you should read about the NOHUP signal. Use nohup at starting of the command in your xterm, so command can keep going on until it gets finished, even after you accidently close the xterm.
See here: http://en.wikipedia.org/wiki/Nohup
Second, a closed xterm cannot be recovered or re-opened. The commands or operations that were running in it may get aborted or become defunct. Thus it's better to run important commands with nohup in xterm, so that can still generate output if xterm closes.

Appreciate the feedback...I'll keep that in mind on my next adventure. The current script actually stays alive even if the window is closed which I haven't exactly wrapped my head around yet. I need to look at the way it is called from the CDE button perhaps.

Anyways....thank you again!


All times are GMT -5. The time now is 05:21 PM.