LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 10-05-2012, 09:44 AM   #1
ruberked
LQ Newbie
 
Registered: Oct 2012
Posts: 4

Rep: Reputation: Disabled
Smile 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!

Last edited by ruberked; 10-05-2012 at 09:52 AM.
 
Old 10-05-2012, 11:55 AM   #2
porphyry5
Member
 
Registered: Jul 2010
Location: oregon usa
Distribution: Slackware 14.1, Arch, Lubuntu 18.04 OpenSUSE Leap 15.x
Posts: 518

Rep: Reputation: 24
Quote:
Originally Posted by ruberked View Post
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
 
Old 10-05-2012, 12:32 PM   #3
ruberked
LQ Newbie
 
Registered: Oct 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by porphyry5 View Post
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?

Shoot...I'm probably taking away the point of creating simple bash scripts and should probably just buck up and learn tcl/tk!
 
Old 10-05-2012, 01:09 PM   #4
porphyry5
Member
 
Registered: Jul 2010
Location: oregon usa
Distribution: Slackware 14.1, Arch, Lubuntu 18.04 OpenSUSE Leap 15.x
Posts: 518

Rep: Reputation: 24
Quote:
Originally Posted by ruberked View Post
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?
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.

Last edited by porphyry5; 10-05-2012 at 01:20 PM.
 
Old 10-05-2012, 01:20 PM   #5
ruberked
LQ Newbie
 
Registered: Oct 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by porphyry5 View Post
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..
 
Old 10-12-2012, 01:59 PM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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.

Last edited by shivaa; 10-12-2012 at 02:00 PM.
 
Old 10-12-2012, 04:51 PM   #7
ruberked
LQ Newbie
 
Registered: Oct 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by meninvenus View Post
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!
 
  


Reply



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
Bash script to update Debian type systems, a couple of questions k3lt01 Programming 24 11-15-2011 08:10 PM
Bash Scripting questions (2) rjcrews Programming 3 04-05-2006 12:14 PM
Bash scripting questions stryka Programming 3 11-24-2005 11:46 PM
bash scripting questions nix101 Linux - Newbie 2 09-04-2005 09:26 AM
Bash scripting questions irfanhab Programming 2 06-07-2004 12:13 PM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 08:13 PM.

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
Open Source Consulting | Domain Registration