Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is it okay for me to check the contents of a file for a given string with grep in an init script?

I am concerned about introducing dependencies and general convention when it comes init scripts, and if running grep or other tools violates some credo.

share|improve this question
    
supposedly you're supposed to use $() versus `backticks` now, but other than that I think you're good. Then again, backticks are more universal though ?deprecated?. Even the most stripped down versions of linux and linuxy OSs have grep. –  khaki54 May 15 '13 at 19:47
1  
When I can do $(string expansion) on stackexchange, then I'll stop using backticks. :) –  mbrownnyc May 16 '13 at 13:11

2 Answers 2

up vote 6 down vote accepted

iniscripts can do whatever they want. Of course it makes sense not to introduce new dependencies, just for the initscripts. grep however is fine on pretty much any system that's posix/susv3 compatible (linux, bsd, solaris, other derivatives).

For more utilities that should always be there, see http://pubs.opengroup.org/onlinepubs/009695399/idx/utilities.html

share|improve this answer
    
Surprised that which isn't on there, but I guess that can be done in in with a shell one-liner. –  mbrownnyc May 16 '13 at 13:13
2  
You can use type instead of which. The functionality is slightly different, but you can get equivalent results. –  Dennis Kaarsemaker May 16 '13 at 13:27

In short, YES. So long as the file you are looking for is mounted at that point.

share|improve this answer
    
I wasn't really asking if it was possible, but I will in fact handle this condition as well, so thanks. –  mbrownnyc May 15 '13 at 19:21
1  
It IS acceptable and you will find that many of the init scripts do this. –  mdpc May 15 '13 at 19:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.