Adding terminal command on start-up, Lion OSX

Discussion in 'Mac Apps and Mac App Store' started by Vegbrain, Jun 17, 2012.

  1. Vegbrain macrumors newbie

    Joined:
    Jun 17, 2012
    #1
    I'm a complete newbee on terminal scripts, so "help", please:
    PROBLEM - I have a Satellite HDR that is running an older W98 version of Samba, and my new Mac (OSX 10.7) can't connect as pre-XP versions of Samba are not recognized.
    SOLUTION: from the Apple website, if I add:
    "sudo sysctl -w net.smb.fs.kern_deprecatePreXPServers=0"
    the problem is solved. But I have to execute this command in the terminal each time I start up the Mac.
    QUESTION - how do I make this change permanent?
    I bought a program called Lingon 3 which was supposed to make it easy, but it won't accept anything starting with "sudo" as it says this is not allowed in the "root"(??). I have no idea what this means.
    Can anybody out there help me, please?
     
  2. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #2
    You can run that shell command in an Applescript as described here, and have it prompt you for your password.

    Once you get the Applescript working properly you can save it as an app then run the app as a login item.
     
  3. Vegbrain thread starter macrumors newbie

    Joined:
    Jun 17, 2012
    #3
    Thanks Weaselboy, but as I haven't a clue about any of this, I can't understand anything about the link you sent. Any chance of providing some really basic instructions, please?
    Thanks in advance.
     
  4. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #4
    Sure thing. Open the Applescript editor app from the /Applications/Utilities folder. Then copy/paste in the below command.

    Code:
    do shell script "sysctl -w net.smb.fs.kern_deprecatePreXPServers=0" with administrator privileges
    Then click the compile button in Applescript editor. Now click the run button to test your script. It should give you a popup window with your user name already filled in and the password window blank. Type in your password and hit return. That should execute the script.

    If it worked okay, you now want to save the Applescript as an application. In Applescript editor click on the file menu then "save as" and name your new app. Toward the bottom of the save as window change the format from script to application. Pick where you want to save your app (I would put it in /Applications) then save it.

    Quit the Applescript editor.

    Now go to System Preferences / Users & Groups and click your user name then add your new app as a login item.

    Logout then log back in. You should get the same password prompt you did earlier when testing. Type in the password and hit enter and your script should execute. You could embed the password in the script, but this is not very safe and exposes your password in a plain text file. The better and safer way is what we did here that prompts for the password each time.

    This should do it. :)
     
  5. Vegbrain thread starter macrumors newbie

    Joined:
    Jun 17, 2012
    #5
    Many many thanks - This works (sort of). It doesn't work from a cold boot, even though I get the prompt on start-up to put in my password for the newly-created app. However, it works fine if I click on the app after boot-up - this is good enough for me. I owe you a pint!:)
     
  6. pitaya macrumors member

    Joined:
    Jun 17, 2012
    #6
    Why don't you try adding that sysctl setting to "/etc/sysctl.conf"? It has a man page, so maybe it will work.

    Code:
    sudo sh -c "echo net.smb.fs.kern_deprecatePreXPServers=0 >> /etc/sysctl.conf"
     
  7. Vegbrain thread starter macrumors newbie

    Joined:
    Jun 17, 2012
    #7
    Thanks pitaya, someone else on the Satellite forum also has just mentioned "/etc/sysctl.conf", but without idiot's-guide instructions I have no idea how to edit things. And what is a man page?
     
  8. pitaya macrumors member

    Joined:
    Jun 17, 2012
    #8
    A man page is a form of text based system documentation. You could think of man as short for manual. 'man' is the command you type in to read a page from the manual. If you open up a Terminal window you can enter the following to read about sysctl.conf.

    Code:
    man sysctl.conf
    From the Description section:
    Code:
    The /etc/sysctl.conf file is read in when the system goes into multi-user mode to
         set default settings for the kernel.
    The sudo command from my previous post will append your setting to the text file /etc/sysctl.conf . Enter that command into a terminal window. You can check the contents using a plain text editor, or:

    Code:
    cat /etc/sysctl.conf


    Also, you can use 'apropos' to search for keywords in man page descriptions:

    Code:
    $ apropos sysctl
    sysctl(3), sysctlbyname(3), sysctlnametomib(3) - get or set system information
    sysctl(8)                - get or set kernel state
    sysctl.conf(5)           - kernel state defaults
    You can then read those man pages using 'man'.
     
  9. Vegbrain thread starter macrumors newbie

    Joined:
    Jun 17, 2012
    #9
    Sorry, I'm missing something basic here, I still don't understand what to do.
     
  10. pitaya macrumors member

    Joined:
    Jun 17, 2012
    #10
    • remove login item
    • open Terminal.app window
    • copy/paste sudo command from above
    • cat /etc/sysctl.conf
    • does it look ok? Yes? Reboot
    • retrieve net.smb.fs.kern_deprecatePreXPServerskernel state (see below). Check that it's now 0

    Code:
    sysctl net.smb.fs.kern_deprecatePreXPServers
     
  11. Vegbrain thread starter macrumors newbie

    Joined:
    Jun 17, 2012
    #11
    Thanks - tried this, and after I enter the "cat /etc/sysctl.conf" script it returns the answer zero, so looks good, but when I reboot and try "sysctl net.smb.fs.kern_deprecatePreXPServers" it says "class not implemented".
     
  12. pitaya, Jun 17, 2012
    Last edited: Jun 17, 2012

    pitaya macrumors member

    Joined:
    Jun 17, 2012
    #12
    Copy and paste exactly what you see in the terminal window, including the output of "cat /etc/sysctl.conf" and the output of the sysctl command line.

    edit: Actually, sysctl.conf isn't working here either. Not sure why yet. You can always fall back on the login item.
     
  13. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #13
    @pitaya Any feedback on the Applescript issue he us having with not working on cold boot, but working on login (warm) boot? You think a "delay 2" at the top of the script is needed to let things settle before the command is run? I'm at a bit of a loss. :confused:
     
  14. pitaya macrumors member

    Joined:
    Jun 17, 2012
    #14
    I don't know. I could try to speculate a little. Check this out:

    Code:
    $ sysctl net.smb.fs.kern_deprecatePreXPServers
    net: class is not implemented
    $ sudo /sbin/kextload /System/Library/Extensions/smbfs.kext
    $ sysctl net.smb.fs.kern_deprecatePreXPServers
    net.smb.fs.kern_deprecatePreXPServers: 1
    That might explain sysctl.conf not working too. If the MIB (that's what the net.smb.... line is called) doesn't exist until a kernel module is loaded (smbfs.kext), and the module tends to get loaded on demand later, then sysctl won't work. So you could try adding that kextload line before the sysctl line in your login item script.

    Another option would be to figure out how to make a StartupItem, or figure out how to easily load a kernel module earlier.
     
  15. kryten2, Jun 17, 2012
    Last edited: Jun 17, 2012

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #15
    From sysctl.conf :

    You could try a delay like Weaselboy said. Or manually loading smbfs.kext like pitaya said. Good thinking guys. Try this :

    Code:
    -- Script is NOT tested!
    set the_command to do shell script "sysctl net.smb.fs.kern_deprecatePreXPServers 2>&1"
    if the_command contains "class is not implemented" then
    	do shell script "kextload /System/Library/Extensions/smbfs.kext" with administrator privileges
    	do shell script "sysctl -w net.smb.fs.kern_deprecatePreXPServers=0" with administrator privileges
    end if
    You can edit /etc/sudoers to get rid of the with administrator privileges.
     
  16. Comeagain? macrumors 68020

    Comeagain?

    Joined:
    Feb 17, 2011
    Location:
    Spokane, WA
  17. Vegbrain thread starter macrumors newbie

    Joined:
    Jun 17, 2012
    #17
    Thanks all, I'll get back to you on this next weekend as I'm traveling all week.
     
  18. mbrennwa macrumors newbie

    Joined:
    Jul 1, 2011
    #18
    Solved!

    Dear all, I was in the same situation: tried to make SMB access work by automatically running the shell command mentioned above. I made it work using launchd to load the smbfs kernel extension and then run the sysctl command (both at boot, as root).

    Here's what I did:

    STEP 1:
    Create a script file (/fixSMBaccess.sh) with the following commands:
    Code:
    /sbin/kextload /System/Library/Extensions/smbfs.kext
    sysctl -w net.smb.fs.kern_deprecatePreXPServers=0
    Make this script executable by running:
    Code:
    sudo chmod +x /fixSMBaccess.sh
    .
    If this script is called at startup (or later), it will set net.smb.fs.kern_deprecatePreXPServers to zero, which allows connecting to SMB shares.

    STEP 2:
    Create the file /Library/LaunchDaemons/com.water.fixSMBaccess.plist containing the following lines:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple$
    <plist version="1.0">
    <dict>
    
    <key>Label</key>
    <string>com.water.fixSMBaccess</string>
    
    <key>Disabled</key>
    <false/>
    
    <key>ProgramArguments</key>
    <array>
    <string>/fixSMBaccess.sh</string>
    </array>
    
    <key>RunAtLoad</key>
    <true/>
    
    <key>StandardErrorPath</key>
    <string>/fixSMBaccess_errors.log</string>
    
    <key>StandardOutPath</key>
    <string>/fixSMBaccess_out.log</string>
    
    </dict>
    </plist>
    This file will tell laundctl to run the above script at boot, so that you should automatically be able to mount SMB shares.

    STEP 3:
    Reboot and hope everything works as expected. If not, complain.
     
  19. NZ-Ben macrumors newbie

    Joined:
    Mar 18, 2013
    #19
    Your problem is that you've got the wrong version of Ligon...
    Ligon 3 (available from the app store) can't do anything as root - nothing from the app store can. What this means for those new to terminal is it can't do anything that starts with "sudo"

    There is another version of Ligon (Ligon X, i think?) that you can download from the writers website that can run sudo (root) commands.
     

Share This Page