Bash scripting to find CPU info and perform action
Hi
I want to create a bash script that would take the CPU ID (either by looking in /proc/cpuinfo or by issuing a vmcp command) and then issuing a command (i.e. ifconfig ethx up). I want to put this somewhere during the boot process. Thanks! |
So what have you done so far and where are you hitting problems?
|
Go on then...
Post it here when you get stuck and we'll help you get it fixed. And I'm going to link ESR here: http://www.catb.org/esr/faqs/smart-questions.html |
Please do not expect a readymade script, as it will give you nothing to learn. But do some hit & trials, search over google, follow any guides... and then if you stuck with any command or syntax or symbols... then we're here to help you.
A shell script is nothing, but a list of commands, but in correct order. In the meantime, I will give you some hints: Code:
#!/bin/bash # Script interpreter |
Thanks guys... though I've coded everything from Cobol to C++, I'm not too sure about shell scripting.
With that said, here is my embarrassing attempt: #!/bin/bash x = FF265 ID = (Not sure how to extract CPU ID from /proc/cpuinfo) if (x = ID) ifconfig eth0 up else ifconfig eth1 up |
#!/bin/bash
x = FF265 ID = grep -w "FF265" /proc/cpuinfo if (x = ID) ifconfig eth0 up else ifconfig eth1 up Now... any ideas on how I can test this? |
#!/bin/bash
x=02FAC6 ID=$(grep -w "02FAC6" /proc/cpuinfo) if [$x = $ID]; then echo "02FAC6" else echo "not 02FAC6" fi Its not liking the comparison on line 4? ./HANetwork.sh: line 4: [02FAC6: command not found[COLOR="Silver"] |
|
That did the trick... and thank you for the links. Good reference tools.
|
This is what I ended up with and it is exactly what I'm looking for. Thanks again for all your help... sorry if the initial question was bad.
#!/bin/bash # # Used to extract CPU ID from /proc/cpuinfo # Compares with x and based on that starts appropriate # Network Interface # x='02FAC6' ID=$(grep -i -r -o -m 1 '02FAC6' /proc/cpuinfo) if [[ "$x" = "$ID" ]]; then ifconfig eth0 up else ifconfig eth1 up fi |
Code:
x='02FAC6' Shell is a subtle beast, there's lots of nuances and tricks that are easiest to pick up from a good book. This is the one on my bookshelf: http://www.amazon.com/Unix-Shell-Pro.../dp/0672324903 |
All times are GMT -5. The time now is 04:22 AM. |