bash - How do I execute sudo subcommand in background -
i have script should run this:
sudo command & othercommand   i need password prompt sudo finish before othercommand run, above setup runs sudo in background rather command
ie, bash doing: (sudo command) & while i'd sudo (command &)
i use sudo -b makes command detatch terminal , makes hard stop since ^c , jobs won't effect it.
how can this?
to able stop background process when script exits example ctrl-c use trap:
trap 'kill $pids' exit [...] sudo command & pids="${pids+$pids }$!" [...] othercommand [...] wait   this script exit once sudo command finished or receives terminating signal, @ point kill sudo command before exiting.
Comments
Post a Comment