ネットワークアドレスにpingを実行できるかどうかに基づいて機能するbashスクリプトがあります。このスクリプトがネットワークの外部で実行される場合がありますが、その場合は実行したくありません。なのでこれをまとめました
if ping -c 1 xxx.xxx.x.x > /dev/null; then
ネットワーク内にある場合、「then」ステートメントは問題なく機能します。ただし、ワイヤレス カードの電源を切り、イーサネット ケーブルを外して「else」をテストするたびに、else ステートメントが実行されることはありません。これを書くべき別の方法はありますか?
これが完全なスクリプトです。
#!/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
ご提案ありがとうございます。