Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > script.command - how to kill Terminal after?

script.command - how to kill Terminal after?
Thread Tools
Big-C
Dedicated MacNNer
Join Date: Apr 2001
Location: Montrose, CA
Status: Offline
Reply With Quote
Mar 11, 2003, 08:38 PM
 
Hi,

I wrote a little script to mount a remote hard drive (thanks to commands found on this board!), and now have 2 questions:

1. Anyone know how to kill the finished Terminal.app when my script is finished?

I tried this:
############################
set pid = `ps aux | grep -v grep | grep Terminal | awk '{print $2}'`

if ($pid != "") then
kill $pid
endif
############################

But my variable $pid echo's as empty when the script runs...


2. Anyone know how I can unmount the mounted disk via my script?


Any help with either of these is appreciated!

-Chris
     
Axel
Mac Enthusiast
Join Date: Sep 2000
Location: France
Status: Offline
Reply With Quote
Mar 12, 2003, 07:35 AM
 
I think that's because without the appropriate flag, the ps command's output is limited by the width of your current Terminal window. You'll see that if you resize it, the script will work.
The easiest way to solve your problem is to add the -w flag to the ps command, that is type :
ps auwx | grep...
     
Arkham_c
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Mar 12, 2003, 11:33 AM
 
To get the PID, (a) don't put spaces between variable name, equals sign, and command, and (b) set is unnecessary if you're using a Bourne shell (as you should for all scripting).

Code:
#!/bin/sh # # kill Terminal # PID=`ps -auxww | grep Terminal.app | grep -v grep | awk '{print $2}'` if [ "$PID" != "" ]; then kill $PID fi
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
Big-C  (op)
Dedicated MacNNer
Join Date: Apr 2001
Location: Montrose, CA
Status: Offline
Reply With Quote
Mar 12, 2003, 03:24 PM
 
Victory!

I'm happy to report that the "ps auxw" option worked perfectly.

Thanks!!

-Chris

PS. I use csh for scripting (it's hard to break old habits).
     
ul1984
Forum Regular
Join Date: Feb 2003
Location: Sundsvall, Sweden
Status: Offline
Reply With Quote
Mar 17, 2003, 01:20 PM
 
Or you could just use a much simpler command:

killall Terminal
     
   
 
Forum Links
Forum 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 On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 10:32 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,