猛击“如果ping则别的”我的其他人不能正常工作

时间:2012-10-04 19:12:53

标签: macos bash

我有一个bash脚本应该根据我是否可以ping我的网络地址而工作。这个脚本会在我的网络之外运行,在这种情况下,我不希望它运行。所以我把这个放在一起

if ping -c 1 xxx.xxx.x.x > /dev/null; then

当它在网络中时,“then”语句就可以了。但是,每当我关闭无线网卡并断开以太网线以测试“其他”时,我的其他声明永远不会被执行。还有其他方法我应该写这个吗?

这是完整的脚本;

#!/bin/bash

computerid=`/usr/sbin/scutil --get LocalHostName`

# Standard parameters
domain="xxx.xxxxxxx.xxx"                            # fully qualified DNS name of Active Directory Domain
udn="xxxxxx"                                            # username of a privileged network user
password="xxxxxx"                                           # password of a privileged network user
ou="OU=MacOS,DC=xxx,DC=xxxxxxx,DC=xxx"              # Distinguished name of container for the computer

# Advanced options
alldomains="enable"                 # 'enable' or 'disable' automatic multi-domain authentication
localhome="enable"                  # 'enable' or 'disable' force home directory to local drive
protocol="smb"                              # 'afp' or 'smb' change how home is mounted from server
mobile="enable"                         # 'enable' or 'disable' mobile account support for offline logon
mobileconfirm="disable"             # 'enable' or 'disable' warn the user that a mobile acct will be created
useuncpath="enable"                 # 'enable' or 'disable' use AD SMBHome attribute to determine the home dir
user_shell="/bin/bash"              # e.g., /bin/bash or "none"
preferred="-preferred xxx.xxxxxx.xxx"       # Use the specified server for all Directory lookups and authentication
# (e.g. "-nopreferred" or "-preferred ad.server.edu")
admingroups="xxx\domain admins,xxx\enterprise admins,xxx\teacher98,xxx\ADManagement - Computers,xxx\admin employees"        # These comma-separated AD groups may administer the machine (e.g. "" or "APPLE\mac admins")

### End of configuration

# Delay the login window by unloading the com.apple.loginwindow
# LaunchDaemon in /System/Library/LaunchDaemons/

launchctl unload -w /System/Library/LaunchDaemons/com.apple.loginwindow.plist


## Wait until all network services are up.
sleep 10

# Check to see if we're in the district
if ping -c 1 xxx.xxx.x.x > /dev/null; then


    #make sure time is set correctly
    ntpdate -u time.xxxxxxx.xxx


    # Activate the AD plugin
    defaults write /Library/Preferences/DirectoryService/DirectoryService "Active Directory" "Active"
    plutil -convert xml1 /Library/Preferences/DirectoryService/DirectoryService.plist
    sleep 5

    # Remove computer from OU
    dsconfigad -f -r -u xxxxxx -p xxxxxx
    sleep 5

    # Bind to AD
    dsconfigad -f -a $computerid -domain $domain -u $udn -p "$password" -ou "$ou"

    # Configure advanced AD plugin options
    if [ "$admingroups" = "" ]; then
        dsconfigad -nogroups
    else
        dsconfigad -groups "$admingroups"
    fi

    dsconfigad -alldomains $alldomains -localhome $localhome -protocol $protocol \
        -mobile $mobile -mobileconfirm $mobileconfirm -useuncpath $useuncpath \
        -shell $user_shell $preferred

    # Restart DirectoryService (necessary to reload AD plugin activation settings)
    killall DirectoryService

    # Add the AD node to the search path
    if [ "$alldomains" = "enable" ]; then
        csp="/Active Directory/All Domains"
    else
        csp="/Active Directory/$domain"
    fi

    # This works in a pinch if the above code does not
    defaults write /Library/Preferences/DirectoryService/SearchNodeConfig "Search Node Custom Path Array" -array "/Active Directory/All Domains"
    defaults write /Library/Preferences/DirectoryService/SearchNodeConfig "Search Policy" -int 4
    defaults write /Library/Preferences/DirectoryService/ContactsNodeConfig "Search Node Custom Path Array" -array "/Active Directory/All Domains"
    defaults write /Library/Preferences/DirectoryService/ContactsNodeConfig "Search Policy" -int 4

    plutil -convert xml1 /Library/Preferences/DirectoryService/SearchNodeConfig.plist

    ## Remove the script and launchd job. Be sure to delete the script. 
    rm /Library/LaunchDaemons/com.xxxx.adbind.plist
    rm /usr/local/bin/adbind.bash
    launchctl unload -w /Library/LaunchDaemons/com.xxxx.adbind.plist

    # Remove the loginwindow delay by loading the com.apple.loginwindow   
    # LaunchDaemon in /System/Library/LaunchDaemons/

    launchctl load -wF /System/Library/LaunchDaemons/com.apple.loginwindow.plist

    exit 0

else

    echo "District not Available Quitting"

    # Remove the loginwindow delay by loading the com.apple.loginwindow   
    # LaunchDaemon in /System/Library/LaunchDaemons/

    launchctl load -wF /System/Library/LaunchDaemons/com.apple.loginwindow.plist

fi

exit 1

感谢您的任何建议!

1 个答案:

答案 0 :(得分:0)

您可能需要使用超时(-W)man ping

相关问题