Quitting apps from the command line`

ericmurphy

Registered
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?
 
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.
 
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.
 
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
 
Back
Top