0
저는 이름과 절대 경로로 새로운 가상 호스트를 추가하는 AppleScript를 작성하려고합니다.AppleScript로 VirtualHost를 만듭니다.
테스트 파일 (바탕 화면의 txt 파일)을 사용할 때 작동하지만 실제 파일 (/ 개인/etc/hosts 및 /private/etc/apache2/extras/httpd-vhosts.conf)을 시도하면 작동합니다 작동하지.
문제는 사용자 권한 주위에있는 것 같지만 관리자로 쓰기 위해 파일을 여는 방법을 모릅니다.
on run (input)
display dialog "New VirtualHost name" default answer ""
set VirtualHostName to text returned of result
display dialog "Absolute path to VirtualHost's root" default answer "/Library/Webserver/Documents"
set VirtualHostRoot to text returned of result
try
set hostsNL to "\n127.0.0.1 " & VirtualHostName
set httpdVhostNL to "\n<VirtualHost 127.0.0.1:80>
ServerAdmin [email protected]
ServerName " & VirtualHostName & ".local
DocumentRoot '" & VirtualHostRoot & "'
ErrorLog '/private/var/log/apache2/" & VirtualHostName & "-error_log'
CustomLog '/private/var/log/apache2/" & VirtualHostName & "-access_log' common </VirtualHost>"
set hosts to open for access (POSIX file "/private/etc/hosts") with write permission
write hostsNL to hosts starting at eof
close access hosts
set httpdVhosts to open for access (POSIX file "/private/etc/apache2/extras/httpd-vhosts.conf") with write permission
write httpdVhostNL to httpdVhosts starting at eof
close access httpdVhosts
do shell script "apachectl graceful" with administrator privileges
return true
on error
try
close access hosts
close access httpdVhosts
end try
return false
end try end run
또는 : 다른 simlpe 방법이 나는
내 코드 (내가 잘못된 구문을 사용하고 아마 AR) '쉘 스크립트를 수행 할'하지만이 작동하지 않습니다 내가 뭘 다만 방법을 시도 가상 호스트를 만드시겠습니까?