[Leaf-user] Simple scripting question
Dear All, I am running an EigerStein-2beta LRP and I want to check if the pppd deamon is still running. I would have done something like: if [ ps ax | grep -v grep | grep -q /usr/sbin/pppd ] then ... else ... fi But... grep doesn't do -v or (I think) -q. This must be simple, could an expert out there help me please? Greetings Mark ___ Leaf-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/leaf-user
Re: [Leaf-user] Simple scripting question
Mark Plowman wrote: But... grep doesn't do -v or (I think) -q. This must be simple, could an expert out there help me please? You could use sed, or use a new version of busybox (which acts as grep). grep -v can be done with sed this way: sed '/pat/d' grep -q could be done this way: $(cat input | sed '/pat/' | wc -l) -ne 0 sed is full GNU sed, whereas grep is busybox's minimalist grep. ___ Leaf-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/leaf-user
Re: [Leaf-user] Simple scripting question
You can generally replace 'wc -l' with sed -n '$=', although you won't get a zero output if there are no lines. I know about this construct, using two (2) sed's: sed -n = | sed -n '$p' On Dachstein-CD: sed -n '$=' returns: sed: -e expression #1, char 1: Unknown command: ``?'' What do you think? Hmm...works for me: krypton.private.network: -root- # sed -n '$=' /etc/network.conf 767 krypton.private.network: -root- # The sed man page from debian lists = as a Zero- or One- address command, and $ is a valid single address... Charles Steinkuehler http://lrp.steinkuehler.net http://c0wz.steinkuehler.net (lrp.c0wz.com mirror) ___ Leaf-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/leaf-user
Re: [Leaf-user] Simple scripting question
Charles Steinkuehler wrote: You can generally replace 'wc -l' with sed -n '$=', although you won't get a zero output if there are no lines. I know about this construct, using two (2) sed's: sed -n = | sed -n '$p' On Dachstein-CD: sed -n '$=' returns: sed: -e expression #1, char 1: Unknown command: ``?'' What do you think? Hmm...works for me: krypton.private.network: -root- # sed -n '$=' /etc/network.conf 767 krypton.private.network: -root- # The sed man page from debian lists = as a Zero- or One- address command, and $ is a valid single address... Yes, from the CLI, as you illustrate, it *does* work. I didn't try that ; However, these *all* fail: sed -n '/ DENY /s/DENY//p' /var/log/kern.log | sed -n '?=' sed: -e expression #1, char 1: Unknown command: ``?'' sed -n '/ DENY /s/DENY//p;?=' /var/log/kern.log sed: -e expression #1, char 19: Unknown command: ``?'' sed -n '/ DENY /s/DENY//;?=' /var/log/kern.log sed: -e expression #1, char 18: Unknown command: ``?'' I want to use sed to filter on [address]: / DENT / perhaps (or not) execute some command: s/DENY// and -- in that same instance of sed -- *count* the lines of output. What do you think? -- Best Regards, mds mds resource 888.250.3987 Dare to fix things before they break . . . Our capacity for understanding is inversely proportional to how much we think we know. The more I know, the more I know I don't know . . . ___ Leaf-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/leaf-user
Re: [Leaf-user] Simple scripting question
Oo, talk about my bad };Þ Charles Steinkuehler wrote: Hmm...works for me: krypton.private.network: -root- # sed -n '$=' /etc/network.conf 767 krypton.private.network: -root- # The sed man page from debian lists = as a Zero- or One- address command, and $ is a valid single address... Yes, from the CLI, as you illustrate, it *does* work. I didn't try that ; However, these *all* fail: sed -n '/ DENY /s/DENY//p' /var/log/kern.log | sed -n '?=' sed: -e expression #1, char 1: Unknown command: ``?'' sed -n '/ DENY /s/DENY//p;?=' /var/log/kern.log sed: -e expression #1, char 19: Unknown command: ``?'' sed -n '/ DENY /s/DENY//;?=' /var/log/kern.log sed: -e expression #1, char 18: Unknown command: ``?'' Try changing the ?= to $=, and maybe it won't complain about the unknown command ? ;-) -- Best Regards, mds mds resource 888.250.3987 Dare to fix things before they break . . . Our capacity for understanding is inversely proportional to how much we think we know. The more I know, the more I know I don't know . . . ___ Leaf-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/leaf-user
Re: [Leaf-user] Simple scripting question
David Douthitt wrote: [snip] $(cat input | sed '/pat/' | wc -l) -ne 0 Remember, only you can prevent a useless use of cat ... :-o ___ Leaf-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/leaf-user