I have been setting up a launch daemon that launch a bash script on demand. However, once I load my launch agent and communicate via socket, then it keep running my bash script every 10 seconds.I've even set KeepAlive flag as false in plist and added delay in bash script, but still it keep running.
How can I set it up to run only once when i connect with the socket.
Plist file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.example.test.helper</string>
<key>Program</key>
<string>/Library/Application Support/test/testexec</string>
<key>ProgramArguments</key>
<array>
<string>/Library/Application Support/test/testexec</string>
</array>
<key>OnDemand</key>
<true/>
<key>KeepAlive</key>
<false/>
<key>Sockets</key>
<dict>
<key>MasterSocket</key>
<dict>
<key>SockFamily</key>
<string>Unix</string>
<key>SockPathMode</key>
<integer>438</integer>
<key>SockPathName</key>
<string>/var/run/com.example.test.helper.socket</string>
<key>SockType</key>
<string>Stream</string>
</dict>
</dict>
</dict>
</plist>
bash script file:
#!/bin/bash
FILE_PATH="/var/log/test.log"
print()
{
echo "$(date +"%m-%d %T") $1" >> $FILE_PATH
}
/bin/rm -r "/private/var/test"
retcode=$?
print "rm returncode: $retcode"
if [ $retcode -ne 0 ];
then
print "The removing failed"
fi
sleep 15