Re: [SLUG] stop processing with 'if grep exit' ?
On Wed, March 19, 2014 5:43 pm, pe...@chubb.wattle.id.au wrote: Yes, but I'd use grep test2 file2 exit 0 Peter, thanks again. can I include somewhere here 'echo 'helo' $LOG' -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] stop processing with 'if grep exit' ?
lists == lists li...@sbt.net.au writes: lists On Wed, March 19, 2014 5:43 pm, pe...@chubb.wattle.id.au wrote: Yes, but I'd use grep test2 file2 exit 0 lists Peter, lists thanks again. can I include somewhere here 'echo 'helo' lists $LOG' Can't see why not. While testing, you can put exec 2 /tmp/alog$$ set +x near the start of the script to get a log of everything that happens in a file in /tmp. Get rid of the lines when you're sure it all works though. If you're doing that, then while testing if there are any lines that you don't want to have their effect, but still want to see, put a colon at the start. : is a special command that does nothing --- but lets you see what arguements would be expanded. So if grep 'stuff3' somefile /dev/null 21 then : mail -s $someSubject f...@nurk.org -EOF Some email message . EOF fi will show the mail command with someSubject exanded in the log, but will not actually send any mail. Peter C lists -- SLUG - Sydney Linux User's Group Mailing List - lists http://slug.org.au/ Subscription info and FAQs: lists http://slug.org.au/faq/mailinglists.html -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] stop processing with 'if grep exit' ?
lists == lists li...@sbt.net.au writes: lists I have a script that runs like this [1]: can I insert another lists grep test 'stuff3' and, stop processing with an 'exit', between lists stuff and stuff2? Yes, but I'd use grep test2 file2 exit 0 Peter C -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] stop processing with 'if grep exit' ?
grep test2 file2 exit 0 Peter, thanks, I'll try that so, I could use multiple conditions like so: grep test2 file2 exit 0 grep test3 file2 exit 0 ? thanks -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] stop processing with 'if grep exit' ?
If you want to grep for multiple strings in the same file, and exit if any of them is found, it is more efficient (and I think more maintainable) to specify them in one line: grep -q -e test2 -e test3 file2 exit 0 The -q is --quiet - just to suppress the output if you aren't interested in it (in this case you are only interested in the exit status, not the output). The -e flag introduces each search term. If the list of strings to look for is longer or variable then you can feed it to grep from a file using -f. See man grep for all the details. On 19 March 2014 18:22, li...@sbt.net.au wrote: grep test2 file2 exit 0 Peter, thanks, I'll try that so, I could use multiple conditions like so: grep test2 file2 exit 0 grep test3 file2 exit 0 ? thanks -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html -- [image: View my profile on LinkedIn] http://www.linkedin.com/in/gliderflyer -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] stop processing with 'if grep exit' ?
On 19 March 2014 22:23, Amos Shapira amos.shap...@gmail.com wrote: If you want to grep for multiple strings in the same file, and exit if any of them is found, it is more efficient (and I think more maintainable) to specify them in one line: grep -q -e test2 -e test3 file2 exit 0 I like this and it probably does what the OP wanted, however it does do a different thing to the original program. The above line will exit the program if test2 is false and test3 is true. The original program required test2 to be true to exit. Yeah, pedantic :-) -- Norman Gaywood, Computer Systems Officer University of New England, Armidale, NSW 2351, Australia ngayw...@une.edu.auPhone: +61 (0)2 6773 2412 http://mcs.une.edu.au/~normFax: +61 (0)2 6773 3312 Please avoid sending me Word or Power Point attachments. See http://www.gnu.org/philosophy/no-word-attachments.html -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
[SLUG] stop processing with 'if grep exit' ?
I have a script that runs like this [1]: can I insert another grep test 'stuff3' and, stop processing with an 'exit', between stuff and stuff2? like these 3 lines in [2] marked '=' [1]- ..snip.. if [ -s /home/voytek/part2 ] ; then if grep -q stuff part2; then if grep 'stuff2' part2; then ..snip.. fi mail -s OK voy...@sbt.net.au oncall.txt fi fi done exit 0 [2]-- ..snip.. if [ -s /home/voytek/part2 ] ; then if grep -q stuff part2; then = if grep -q stuff3 part2; then = exit = fi if grep 'stuff2' part2; then ..snip.. fi mail -s OK voy...@sbt.net.au oncall.txt fi fi done exit 0 -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html