is there way execute bash script when click program netbeans or dropbox on ubuntu , execute bash script when exit
my idea create bash script on cronjob @reboot check every second if program exist in current processes
#!/bin/bash nameofprogram="netbeans" while [[ true ]]; countofprocess=$(ps -ef |grep $nameofprogram | wc -l) if [[ $countofprocess -gt 1 ]]; #execute bash fi sleep 1 done
but think idea not best ,is there better way achieve it?
a better approach wrap executable in script. means put script name of program in path (probably $home/bin
) , linux use instead of real executable.
now can execute real program using:
/usr/bin/netbeans "$@"
so execute real executable, put absolute path in front of name. odd "$@"
pass on arguments might have given script.
put loop around this:
while [[ true ]]; /usr/bin/netbeans "$@" done
but there problem: can't exit program anymore. try, restarts. if want restart when crashes:
while [[ true ]]; /usr/bin/netbeans "$@" && exit 0 done
as long program exits because of error, restarted. if quit it, script stop.
Comments
Post a Comment