|
#1
| |||
| |||
| 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? |
|
#2
| ||||
| ||||
| Use Activity Monitor to get the PID.
__________________ |
|
#3
| |||
| |||
| 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. |
|
#4
| |||
| |||
| 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 |
|
#5
| ||||
| ||||
| 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... |
|
#6
| ||||
| ||||
| 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 |