Women in Technology

Hear us Roar



Article:
  Scripting Mac OS X
Subject:   loginhook
Date:   2004-03-04 10:10:02
From:   yantheman
Good article thanks.
I'm stuck running commands in my login script in 10.3 and I'm having trouble with paths.
Here's my test login hook script:


#!/bin/sh
/usr/bin/touch ~$1/Library/Preferences/thisisatest.txt
exit 0
# end


'sudo testscript.sh yan' gives 'touch: /Users/yan/Preferences/thisisatest.txt: No such file or directory'


The command works fine out of the script.
I need to use a relative path to find the users home folder because some of my users are in /Users and some are in /network for networked home folder. Any ideas would be appreciated.

Full Threads Oldest First

Showing messages 1 through 3 of 3.

  • loginhook
    2004-03-04 13:26:16  jamesreynolds [View]

    $1 for a shell script is the first variable passed into the script. The Loginwindow passes in the username only, not "/Users/". I don't know why you got the error you did. I got:

    touch: ~james/Library/Preferences/thisisatest.txt: No such file or directory

    If I changed the script to:

    /usr/bin/touch /Users/$1/Library/Preferences/thisisatest.txt

    then it works.
    • loginhook
      2004-03-04 14:26:25  yantheman [View]

      This works for me to, but what if users folders aren't always in located in /Users? This is a common with dynamically mounted home folders. The path to the users folder is sometimes /network/volumes.. etc.
      Can a solution be found to use relative paths here?

      Loginhook script runs as root.. Interestingly this command in the script works. Prefs management in Mac OS X is excellent.

      /usr/bin/sudo -u $1 /usr/bin/defaults write com.apple.print.PrintingPrefs DefaultPaperID -string "iso-a4"

      • loginhook
        2004-03-04 14:35:07  jamesreynolds [View]

        > Can a solution be found to use relative paths here?

        Sure. See:

        http://www.macosxlabs.org/documentation/hard_disk_maintenance/configuration/config.html