A
A
aleksey0052014-05-26 06:37:55
bash
aleksey005, 2014-05-26 06:37:55

Why doesn't this bash construct work?

I'm trying to figure out why this bash script doesn't work:

#!/bin/bash
FILE=$1
while read line; do
     echo "MAC : $line"
     PID=$(ps aux | grep "$line" | grep -v "grep" | awk {'print $2'})
     echo "PID : $PID"
done < $FILE

The file contains a list of MAC addresses, one address per line.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aleksey005, 2014-05-26
@aleksey005

I redid the script, probably it was the line break character (the file was made in Windows):
Now everything works like this:

#!/bin/bash
FILE=$1
while read line; do
     echo "MAC : $line"
     MAC=$(echo "$line" | cut -c 1-17)
     PID=$(ps aux | grep $MAC | grep -v "grep" | awk {'print $2'})
     echo "PID : $PID"
done < $FILE

I call the script like this:
./script /путь/до/файла/файл

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question