从我的原生osx应用程序调用bash脚本,该应用程序将我的mac上的本地目录同步到远程服务器。
bash脚本使用以下库:
应用程序控制台上的错误消息:
watch.sh:line 4:/ usr / local / bin / rsync:不允许操作 watch.sh:line 6:/ usr / local / bin / fswatch:不允许操作
System Integrity Protection
,但不会对错误产生任何影响。//////////////////////////////////////////
// FUNCTION - VIEW DID LOAD
override func viewDidLoad() {
super.viewDidLoad()
command(args: "sh","watch.sh")
} // END - FUNCTION
////////////////////////////////////////////
// FUNCTION - COMMAND
func command(args: String...) {
// GET SCRIPTS PATH
let scriptsDir = Bundle.main.resourceURL!.appendingPathComponent("scripts").path
// CREATE A PROCESS INSTANCE
let process = Process()
// SET THE PROCESS PARAMETERS
process.launchPath = "/usr/bin/env"
process.currentDirectoryPath = scriptsDir
process.arguments = args
// CREATE A PIPE AND MAKE THE PROCESS
// PUT ALL THE OUTPUT THERE
let pipe = Pipe()
process.standardOutput = pipe
// LAUNCH THE PROCESS
process.launch()
// GET THE DATA
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
print(output!)
} // END - FUNCTION
#!/bin/bash
/usr/local/bin/rsync --rsh="/usr/local/bin/sshpass -p ************* ssh -l username" -azP --delete "/path/to/local" username@111.111.111.111:/path/to/remote
/usr/local/bin/fswatch -o "/path/to/local" | while read f; do
/usr/local/bin/rsync --rsh="/usr/local/bin/sshpass -p ************* ssh -l username" -azP --delete "/path/to/local" username@111.111.111.111:/path/to/remote
done