I'm trying to run a script that runs opensnoop, outputs the data to a log and kills the process after 15 minutes. However, when the script ends, the log file continues to grow, suggesting that opensnoop is not actually shut down.
It also prompts the user a few times for their password. This is in an attempt to narrow down a problem we've been having on Macs on our network:
#!/bin/sh
filename=~/Desktop/$(hostname)-$(date +"%m-%d-%Y").log
osascript -e 'display dialog "Please enter your password in the terminal window that just opened. The terminal window will not show you entering anything. This is expected behavior."'
sudo opensnoop -v -n apptolog >> $filename & sleep 10
osascript -e 'display dialog "Please enter your password again in the terminal window."'
kill $(jobs -p) >> /dev/null
sleep 5
textblock="The VShield log has been created. Please email <my e-mail> with the subject OpenSnoop logs for Macos and attach $filename."
osascript -e "display dialog \"$textblock\""
Using the above script, and adding jobs -p references, it looks like the command name is just "sudo" and doesn't give the actual command name "opensnoop".
What am I doing wrong here?