Any Mac users here? I would like to run the following Terminal commands on startup:


Code:
sudo /opt/local/libexec/portsentry -tcp
sudo /opt/local/libexec/portsentry -udp


I have tried creating a Workflow with automator and adding it to Startup Items and looking through the system library files for the startup scripts, but can't find them. Any help would be appreciated.
Under System Preferences, go to "Users & Groups" click on your user and select the "Login Items" tab. Add your automator work flow there.
comicIDIOT wrote:
Under System Preferences, go to "Users & Groups" click on your user and select the "Login Items" tab. Add your automator work flow there.


Yes, I did that. It tells me Error. Meanwhile the script works when I invoke it from the command line.
Oh, I didn't read that part. What error?
First it said "the script invoked does not exist" or something like that. Now it just says 255.
You need to use launchd, or whitelist those commands with sudo to run non-interactively.

https://discussions.apple.com/thread/2459271?start=0&tstart=0
Yes, I've been trying that too. No luck.
launchd, or the whitelist? Instead of trying to make an automator workflow, just write a quick shellscript and chmod +x


Code:

#!/bin/bash
sudo /opt/local/libexec/portsentry -tcp
sudo /opt/local/libexec/portsentry -udp
And then use System Preferences to run it on Startup?

That code says No tty present and no askpass program specified.
https://www.google.com/search?q=No+tty+present+and+no+askpass+program+specified
Well, I have some conflicting information...

First off. 'launchd'. I tried to create a script, but it obviously doesn't work. It should be an XML file, right? How should it be set up? Can someone explain it to me in a way that is not cryptic, like the help online? And, where do I drop the file, on OS X 10.8? Do I need to anything else, besides create the file and move it into the right directory, to get it to run on startup?

Secondly, the 'sudo' thing. Some sources say that when the computer is launching an item on startup, it is technically a system process, and the system has root privileges, by default. Is that not true?
Pretty sure launchd will give your process root privileges if you do it right, but I doubt Login Items will.


Open a terminal (I prefer iTerm, but the builtin Terminal app is fine too), and type "man launchd" and hit enter.
elfprince13 wrote:
Pretty sure launchd will give your process root privileges if you do it right, but I doubt Login Items will.


Ok, sounds good. Now how would I write a launchd process? I've looked at the Apple help files and on google and I don't understand it...
Quote:
Open a terminal (I prefer iTerm, but the builtin Terminal app is fine too), and type "man launchd" and hit enter.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST
1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>PortSentryStart</string>
<key>UserName</key>
<string>ROOT</string>
<key>GroupName</key>
<string>WHEEL</string>
<key>ProgramArguments</key>
<array>
<string>/opt/local/libexec/portsentry -tcp</string>
<string>/opt/local/libexec/portsentry -udp</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Have you tested loading it with launchctl?
Just did... launchctl load /Path/to/file

No errors in terminal.

Console...

11/16/12 12:49:18.729 PM com.apple.launchd.peruser.502[248]: (PortSentryStart) Ignored this key: UserName

11/16/12 12:49:18.729 PM com.apple.launchd.peruser.502[248]: (PortSentryStart) Ignored this key: GroupName

11/16/12 12:49:18.740 PM com.apple.launchd.peruser.502[248]: (PortSentryStart[58442]) Job failed to exec(3). Setting up event to tell us when to try again: 2: No such file or directory

11/16/12 12:49:18.743 PM com.apple.launchd.peruser.502[248]: (PortSentryStart[58442]) Job failed to exec(3) for weird reason: 2
type


Code:
ps aux | grep portsentry
(or just ps aux if that doesn't show anything and scroll through manually to see if it appears to be running)
try running that launchctl command with sudo, since you want it to launch with administrative privileges. Additionally, see what happens if you have only 1 of the commands set to run.
launchctl: Dubious ownership on file (skipping): /Users/acagliano/Desktop/portsentry.plist
nothing found to load
ACMBP:~ acagliano$
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement