bash scripting and tr
Hello I am tring to get the MAC address from windows xp and remove it from a file on a unix box. This is what I have so far:
getmac | plink.exe -ssh -pw "my pw" -noagent -m commands.txt root@192.168.1.82 commands.txt cd /root tr '-' ':' | tr -d '[:blank:]' now this is what I get 10:9A:CD:5F:04:8A\Device\Tcpip_{5A79FE8D:F227:4B91:9459:2701486C5D94} All I need is the MAC. Everything after \Device* is not needed. The file is /var/db/captiveportal_mac.db. The MAC address are listed like this. MAC1 MAC2 MAC3 MAC4 MAC5 If there is anything that you can help with, I would love. |
Assuming I'm understanding your request, try:
Code:
cut -d '\' -f 1 |
Thank you for you help. I forgot about the cut command. Now what about taking the now clean MAC address and removing it from that .db file.
|
Code:
sed "/address/d" filename I'm still not completely sure what you're doing though. It would be better if we had actual examples of all the text involved, both before and after. If you use a goal-oriented "I have A, and I want it to look like B" approach, rather than asking about using specific tools, you'll probably get better advice, as there are usually several ways to accomplish such tasks. I'd be willing to bet that you could do it all with a single sed or awk command, instead of a chain of smaller steps. |
Can sed take input from a | or >.
What I am trying to do. I am have 40 public computer at a local library. We need to show the user a page with a usage page before they can get online. We have been using pfsense 1.2.3 with pfsense captive portal and love it. We want the user to seat down at the computer and after opening IE to get a page, after hitting accept they can get on the internet. Pfsense will record the MAC address in a file on pfsense. I need something that will read the MAC for the computer, then login to pfsense and remove the MAC from the file. |
Why don't you try it and find out? Or check out the man page?
Giving actual representative examples of the text you want to process is many times more useful than just explaining vaguely what you want to do. And don't forget the [code][/code] tags. |
This is what I have and I am stuck.
commands.txt Code:
tr '-' ':' | tr -d '[:blank:]' | cut -c1-17 | sed -e /var/db/captiveportal_mac.db |
anyone got any help?
|
:banghead:
For the third time, we really need to see what the input text looks like. Knowing what commands you're using doesn't mean much if we don't know the format of the text they are being applied to. Please show us everything you want to change, step by step, and in detail. Give us the exact output of the command(s) you're using and the exact contents of the text file(s) you want to process, before you've done anything to them, as well as how you want them to look after you're finished. |
This is what win xp gives me after running "getmac"
Code:
00-26-B9-19-B8-0D \Device\Tcpip_{2EA74C88-F5A0-4614-87F7-47B3E1713485} Code:
getmac | plink.exe -ssh -pw (my pw) -noagent -m commands.txt root@192.168.1.82 Code:
cd /root Code:
00:26:B9:19:B8:0D I have got all the way thur and after the Code:
cut -c1-17 Code:
00:26:B9:19:B8:0D |
Ok, that's starting to get us closer. But your procedure is still highly confusing.
1. You want to collect the mac address from the output of getmac. -- but how? Where and how do you actually store this output? And how are you running this anyway--from a cygwin terminal, for example? 2. You then send it to the unix box. -- how? Your commands.txt doesn't contain any of the output from above. So what is this file anyway? Is it a script that gets executed on the unix box? What exactly is it supposed to do? If I'm following it, it's supposed to contain or retrieve the mac address somehow, then once transferred to the other box it's supposed to edit the mac.db file somehow. Am I correct? By the way, the command you have there is completely wrong. sed can work either on the contents of a file, or on text coming into it from stdin, but not on both at the same time. It seems to me that you really have to think this thing through a bit more carefully. Again, if I'm following you, what you really want to do is get the mac address from one computer, and use it to edit a file on a second computer. So there are really three separate operations involved: a) Retrieve the mac address from the Win box. b) Transfer it to the Unix box. c) Use it to edit the db file on the Unix box. So please tell me how you plan to handle each separate step. Edit: One more thing. Your last line says you can't rewrite the file? How can you expect to edit the file if you can't rewrite it? That's what editing is, after all. Edit2: Ok, I see now that you are trying to pipe the output of getmac straight into plink.exe, whatever that is. But does plink.exe even work that way? And even if it does, does it then also execute the commands stored in commands.txt and apply them to the input that it's getting from that pipe? Somehow I really don't think it's supposed to work that way. |
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
What I need help with is how do I remove the MAC out of the mac.db file. |
All times are GMT -5. The time now is 09:18 PM. |