+ Post New Thread
Results 1 to 11 of 11
Mac Thread, Problem with script in Technical; I have a script that mounts a couple of shares to the users desktop. I added it the default login ...
  1. #1
    Arcath's Avatar
    Join Date
    Feb 2009
    Location
    Lancashire
    Posts
    972
    Thank Post
    102
    Thanked 116 Times in 101 Posts
    Rep Power
    74

    Problem with script

    I have a script that mounts a couple of shares to the users desktop. I added it the default login hooks and it runs on ling the only problem is that it wont pickup the username properly.

    Ive tried 3 ways of getting the username:

    $USER

    regexing the output of users

    /usr/bin/logname

    the first 2 return nothing on login and the last one returns "root".

    from what i can tell the script runs as root, is there any way to pickup what the user had typed into the login box?

  2. #2
    AIT
    AIT is offline
    AIT's Avatar
    Join Date
    Dec 2009
    Location
    Nottingham
    Posts
    369
    Thank Post
    46
    Thanked 32 Times in 30 Posts
    Rep Power
    19
    Quote Originally Posted by Arcath View Post
    I have a script that mounts a couple of shares to the users desktop. I added it the default login hooks and it runs on ling the only problem is that it wont pickup the username properly.

    Ive tried 3 ways of getting the username:

    $USER

    regexing the output of users

    /usr/bin/logname

    the first 2 return nothing on login and the last one returns "root".

    from what i can tell the script runs as root, is there any way to pickup what the user had typed into the login box?
    what script is tthis.. bat? vb?

    have u done %username%

  3. #3
    Arcath's Avatar
    Join Date
    Feb 2009
    Location
    Lancashire
    Posts
    972
    Thank Post
    102
    Thanked 116 Times in 101 Posts
    Rep Power
    74
    Ruby or BASH or Apple Script i use all 3 in the script

  4. #4

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,680
    Thank Post
    516
    Thanked 2,451 Times in 1,897 Posts
    Blog Entries
    24
    Rep Power
    832
    How about this AppleScript snippet?
    Code:
    set MyName to do shell script "whoami"
    Then you can just use the MyName variable.

    eg.

    Code:
    set MyName to do shell script "whoami"
    display alert MyName
    Last edited by localzuk; 11th December 2009 at 11:47 AM.

  5. #5
    Arcath's Avatar
    Join Date
    Feb 2009
    Location
    Lancashire
    Posts
    972
    Thank Post
    102
    Thanked 116 Times in 101 Posts
    Rep Power
    74
    whoami returns root

  6. #6

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,680
    Thank Post
    516
    Thanked 2,451 Times in 1,897 Posts
    Blog Entries
    24
    Rep Power
    832
    Quote Originally Posted by Arcath View Post
    whoami returns root
    Ah, ok. It turns out that login hooks always run as root. The variable $1 returns the logging in user apparently?

    Mac OS X: Creating a login hook

  7. #7
    Arcath's Avatar
    Join Date
    Feb 2009
    Location
    Lancashire
    Posts
    972
    Thank Post
    102
    Thanked 116 Times in 101 Posts
    Rep Power
    74
    Quote Originally Posted by localzuk View Post
    Ah, ok. It turns out that login hooks always run as root. The variable $1 returns the logging in user apparently?
    Thanks, its passed as the first argument to the hook, so in ruby its "ARGV[0]"

  8. #8
    Arcath's Avatar
    Join Date
    Feb 2009
    Location
    Lancashire
    Posts
    972
    Thank Post
    102
    Thanked 116 Times in 101 Posts
    Rep Power
    74
    Next issue with the same script

    it mounts a samba share when i test it but when running as a login hook it doesnt mount, it creates the directory no problem but mount_smbfs doesnt seem to work

    is there a log where i can find out why it fails?

  9. #9

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,680
    Thank Post
    516
    Thanked 2,451 Times in 1,897 Posts
    Blog Entries
    24
    Rep Power
    832
    Not sure which log you'd want, but there are a good number of logs in /var/log including a samba directory.

    You could also output the result of the command to a file yourself.

  10. #10
    Arcath's Avatar
    Join Date
    Feb 2009
    Location
    Lancashire
    Posts
    972
    Thank Post
    102
    Thanked 116 Times in 101 Posts
    Rep Power
    74
    Ive put the output into a .txt file and its empty...

  11. #11


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,588
    Thank Post
    228
    Thanked 856 Times in 735 Posts
    Rep Power
    296
    Code:
    set MyName to do shell script "whoami"
    tell application "Finder"
    try
    mount volume "smb://server.domain.local/" & MyName & "$"
    do shell script "ln -s /Volumes/" & MyName & "$ ~/Desktop"
    end try
    try
    mount volume "smb://server.domain.loca/" & "resources$"
    do shell script "ln -s /Volumes/" & "resources$" & " ~/Desktop"
    end try
    try
    mount volume "smb://server.domain.loca/" & "multimedia$"
    do shell script "ln -s /Volumes/" & "resources$" & " ~/Desktop"
    end try
    end tell

SHARE:
+ Post New Thread

Similar Threads

  1. Report A Problem Script
    By russdev in forum Scripts
    Replies: 4
    Last Post: 11th January 2011, 08:50 AM
  2. Desktop Icon script problem.
    By Disease in forum Scripts
    Replies: 5
    Last Post: 6th March 2009, 12:01 PM
  3. logon script problem
    By maark in forum Windows
    Replies: 4
    Last Post: 3rd September 2008, 04:00 PM
  4. Start Menu Script Problem
    By phillipmillward in forum Windows
    Replies: 4
    Last Post: 23rd November 2006, 08:50 AM
  5. Login script problem
    By SpuffMonkey in forum Windows
    Replies: 55
    Last Post: 4th February 2006, 09:27 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •