Hi - I am not an expert at shell script writing. If /proc/cmdline looks like option1 option2 ... ks=http://192.168.1.8/ks/ks.cfg option3 option 4 ... How can I get the 192.168.1.8 out of this cmdline. THanks, Jerry
On Fri, Mar 7, 2008 at 10:35 AM, Jerry Geis <geisj at pagestation.com> wrote:> If /proc/cmdline looks like > > option1 option2 ... ks=http://192.168.1.8/ks/ks.cfg option3 option 4 ... > > How can I get the 192.168.1.8 out of this cmdline.Cryptic but does the job: $ cat /tmp/cmdline option1 option2 ... ks=http://192.168.1.8/ks/ks.cfg option3 option 4 ... $ perl -lane 'm#^ks=.*//((\d+\.){3}\d+)/#&&print($1)&&exit for at F' /tmp/cmdline 192.168.1.8 $ Obviously, you should use /proc/cmdline instead of the file in /tmp as I used. Filipe
> Hi - I am not an expert at shell script writing.Me neither, Perl is my thing, and with regular expressions this would be trivial.> If /proc/cmdline looks like > > option1 option2 ... ks=http://192.168.1.8/ks/ks.cfg option3 option > 4 ... > > How can I get the 192.168.1.8 out of this cmdline.This is probably not the best approach, but it should work: awk -F "ks=" /proc/cmdline '{print $2}' | awk -F / '{print $3}' On the other hand, if I can call awk, I could also call Perl... Alfred
Jerry Geis wrote:> > Hi - I am not an expert at shell script writing. > If /proc/cmdline looks like > > option1 option2 ... ks=http://192.168.1.8/ks/ks.cfg option3 > option 4 ... > > How can I get the 192.168.1.8 out of this cmdline.Try: # IPADDR=`cat /proc/cmdline | sed 's/.*\/\([1-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)\/.*/\1/'` This will find an IP in between /.../ -Ross ______________________________________________________________________ This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified that any dissemination, distribution or copying of this e-mail, and any attachments thereto, is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender and permanently delete the original and any copy or printout thereof. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3971 bytes Desc: not available URL: <http://lists.centos.org/pipermail/centos/attachments/20080307/7bb0cf50/attachment-0002.bin>