image
image

Go Back   macosx.com > Mac Help Forums > Mac OS X System & Mac Software

Reply
 
Thread Tools
  #1  
Old January 31st, 2005, 04:33 PM
Registered User
 
Join Date: Sep 2000
Location: San Francisco
Posts: 222
Thanks: 0
Thanked 0 Times in 0 Posts
ericmurphy is on a distinguished road
Quitting apps from the command line`

Here's the deal: I run OSXVNC to connect to my Mac from work. I don't like the VNC server running when I'm not at work, because VNC's not that secure, and I'd prefer it not run unless I'm using it.

I have a cron job that starts the server in the morning, while I'm on my way to work. If I remember, I quit the server when I get home. But I often forget. So it would be nice to schedule a cron job that would stop the server. Since the server doesn't open or save any files, I could probably just kill the process, but I'd need to get the PID. Is there an easier way to do it, by referring to its application name? Is there a Unix command that analogizes to, e.g., /usr/bin/open /Applications/osxvnc.app?
Reply With Quote
  #2  
Old January 31st, 2005, 04:36 PM
bobw's Avatar
The Late: SuperMacMod
 
Join Date: Mar 2001
Location: Phila,PA
Posts: 8,835
Thanks: 0
Thanked 5 Times in 1 Post
bobw has a spectacular aura aboutbobw has a spectacular aura about
Use Activity Monitor to get the PID.
__________________

Reply With Quote
  #3  
Old January 31st, 2005, 04:41 PM
Registered User
 
Join Date: Sep 2000
Location: San Francisco
Posts: 222
Thanks: 0
Thanked 0 Times in 0 Posts
ericmurphy is on a distinguished road
How's that going to work for a cron job? The PID changes every time the app launches. I'd need to build a script or something that would get the PID and then kill that process.
Reply With Quote
  #4  
Old February 1st, 2005, 12:43 PM
Registered User
 
Join Date: Jun 2003
Posts: 700
Thanks: 0
Thanked 0 Times in 0 Posts
Lycander is on a distinguished road
I've been searching around, can't find a definite answer. Most *nix OSes write a *.pid file (ex: vnc.pid) that contains the proccess ID. The problem is, I can't figure out where those pid files are stored in OSX (I'm at work, my iBook at home). Can't find it on Google either, so maybe have a peek for yourself?

All I found is it's either in /proc or /var/run

If you know some shell scripting, it's quite easy to search for a file (vnc.pid) in a given folder, open it and read the content, then use that to kill the process.

Is OSXNVC a GUI app or command line? I'm more used to using non-GUI VNC programs, to stop it I just use a command like:

# vnc -kill

and it safely brings down the vnc server. That would be the command to run in the cron job.

But if OSXVNC is a GUI app, um... perhaps what you want is an AppleScript, probably a more flexible API, more commands, then schedule that script to run.
__________________
vacant lot
Reply With Quote
  #5  
Old February 1st, 2005, 12:48 PM
brianleahy's Avatar
Colonel Panic
 
Join Date: Sep 2000
Location: Northern Ohio
Posts: 1,579
Thanks: 0
Thanked 0 Times in 0 Posts
brianleahy is on a distinguished road
You could try something like:

kill `ps -e |grep vnc |cut -c1-6 `

This works in HPUX, I think it will in Darwin.

Note the BACKWARD single quotes - found on the same key as the ~

ps -e = list all processes with pid's

|grep vnc = keep only lines containing 'vnc'

|cut -c1-6 = extract characters 1 through 6
__________________
OS X 10.4
G5 Dual 2GHZ / 160GB / 1GB RAM / Superdrive
Apple 20" Cinema Display
SmartDrive 120GB Firewire HD
Maxtor 250GB SATA


Visit my wife's eBay store !!

http://stores.ebay.com/Catchy-Creations-by-brendaonline

Now pining for a MacBook Pro...
Reply With Quote
  #6  
Old February 1st, 2005, 06:48 PM
Darkshadow's Avatar
wandering shadow
 
Join Date: Jul 2001
Location: DE, USA
Posts: 1,532
Thanks: 0
Thanked 0 Times in 0 Posts
Darkshadow is on a distinguished road
I made a small command line program that gets the PID of processes by name. It matches like grep, though, so if there are different programs with similar names, it will list them all (as would grep). vnc should be pretty safe from that, though.

You can download it if you want to try it:

http://homepage.mac.com/darkshadow02/cli.htm#pidof
__________________
I am but a lonely shadow,
Doomed forever to roam and wander.
But if you allow me to pause before I must go,
I'll spin you tales of mystery and wonder.


Site: Night Productions
Reply With Quote
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -5. The time now is 01:49 PM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.