I have about 5-6 daemons specific to my application running in the background. I am trying to write a script to stop them. Usually, I run them as a non-root ID, which is fine. But for some reason the client insists on using root.
By 'client', do you mean the person/company paying you or client software?
If it's the former, tell them that they will not be supported, or perhaps get them to run the stop script as root.
If it is client software, then presumably somewhere there is a root-owned & SUID executable somewhere that is called in the start-up. Find that and take away the SUID.
Client as in my company. Who is running the daemon as non root when its not really needed. I've seen several implementations of this product but never seen the daemon running as root.
The [ ] are special in shell and need to be escaped.
Say you have a file program in your current directory, then the shell replaces [p]rogram by the matching program , and the grep can find its own arguments in the ps args.
Safe is grep "[p]rogram" . (It's a good habit to always put the grep argument in quotes!)
Another problem is that xargs runs the kill without arguments if nothing matches.
Suggestion