From bf3c8d0dfd9e0a3c8a9fe2007d7a499ca416e093 Mon Sep 17 00:00:00 2001 From: Donald Burr Date: Thu, 19 Feb 2015 02:09:17 -0800 Subject: [PATCH] Fixed up crap --- acatcher/MASTER_LIST | 32 +++ acatcher/ROOMS.thu | 2 + acatcher/acatcher.cxx | 478 -------------------------------- acatcher/mkacatcher_cpp.sh | 34 ++- acatcher/mkhosts.sh | 17 +- acatcher/provision_streamers.sh | 34 ++- acatcher/start_streamers.sh | 24 +- acatcher/stop_streamers.sh | 23 +- 8 files changed, 107 insertions(+), 537 deletions(-) create mode 100644 acatcher/MASTER_LIST create mode 100644 acatcher/ROOMS.thu delete mode 100644 acatcher/acatcher.cxx diff --git a/acatcher/MASTER_LIST b/acatcher/MASTER_LIST new file mode 100644 index 0000000..5cdfc17 --- /dev/null +++ b/acatcher/MASTER_LIST @@ -0,0 +1,32 @@ +# V4 Network: 172.16.11.0/24 +# V4 Gateway: 172.16.11.1 +# V4 DNS: 172.16.3.5 +# V4 NTP: 172.16.3.5 +# +# V6 Network: 2607:ff38:3:8109::/64 +# V6 Gateway: Auto +# V6 DNS: 2607:ff38:3:8101::5 +# V6 NTP: 2607:ff38:3:8101::5 +# +# Your Static / Reserved range is: 172.16.11.11-100 +# +e0:3f:49:a1:63:97|172.16.11.11|mon-server +b8:27:eb:a7:af:7f|172.16.11.26|mon-century-ab +b8:27:eb:aa:e9:9f|172.16.11.27|mon-century-cd +b8:27:eb:72:6c:7f|172.16.11.28|mon-lajolla +b8:27:eb:80:c5:10|172.16.11.29|mon-carmel +b8:27:eb:95:dd:7f|172.16.11.30|mon-losangeles-a +b8:27:eb:d8:c1:d9|172.16.11.31|mon-losangeles-b +b8:27:eb:9f:72:e1|172.16.11.32|mon-losangeles-c +b8:27:eb:77:a8:67|172.16.11.33|mon-marina +b8:27:eb:ee:f0:01|172.16.11.34|mon-belair +b8:27:eb:96:ea:02|172.16.11.35|mon-sanlorenzo-d +b8:27:eb:24:9a:b9|172.16.11.36|mon-sanlorenzo-e +b8:27:eb:83:c7:f8|172.16.11.37|mon-sanlorenzo-f +b8:27:eb:cd:b9:cf|172.16.11.38|mon-plaza-bc +b8:27:eb:be:7a:2d|172.16.11.39|mon-plaza-d +b8:27:eb:c3:63:fd|172.16.11.40|mon-internationallballroom +b8:27:eb:f6:bf:8c|172.16.11.41|mon-pacificballroom +b8:27:eb:a9:92:6d|172.16.11.42|mon-spare1 +b8:27:eb:da:5f:67|172.16.11.43|mon-spare2 +f0:de:f1:4d:6d:a9|172.16.11.44|mon-laptop \ No newline at end of file diff --git a/acatcher/ROOMS.thu b/acatcher/ROOMS.thu new file mode 100644 index 0000000..1168168 --- /dev/null +++ b/acatcher/ROOMS.thu @@ -0,0 +1,2 @@ +mon-carmel +mon-losangeles-c diff --git a/acatcher/acatcher.cxx b/acatcher/acatcher.cxx deleted file mode 100644 index ca86024..0000000 --- a/acatcher/acatcher.cxx +++ /dev/null @@ -1,478 +0,0 @@ -/* -awatcher.cxx - -Copyright (c) 2015 Chad Page - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -using namespace cv; -using namespace std; - -const int MAX = 16; - -const char *names[] = { -"[0] mon-century-ab", -"[1] mon-century-cd", -"[2] mon-lajolla", -"[3] mon-carmel", -"[4] mon-losangeles-a", -"[5] mon-losangeles-b", -"[6] mon-losangeles-c", -"[7] mon-marina", -"[8] mon-belair", -"[9] mon-sanlorenzo-d", -"[a] mon-sanlorenzo-e", -"[b] mon-sanlorenzo-f", -"[c] mon-plaza-bc", -"[d] mon-plaza-d", -"[e] mon-internationallballroom", -"[f] mon-pacificballroom", -}; - -void cls() -{ - cerr << "\x1B[2J\x1B[H"; -} - -int baseport = 4000; - -const int BUFLEN = 1024*1024; // in bytes -//const int ABUFLEN = 1024; // in words - -// Yes this is ugly. :P -bool failure = false; - -bool f_showall = false; -bool f_saveaudio = false; - -struct sockin { - int listener_fd, data_fd; - struct sockaddr_in serv_addr, cli_addr; - int id; - - sockin(int _id = 0, int baseport = 5000) { - int option = 1; - - id = _id; - listener_fd = data_fd = -1; - bzero(&serv_addr, sizeof(serv_addr)); - bzero(&cli_addr, sizeof(cli_addr)); - - listener_fd = socket(AF_INET, SOCK_STREAM, 0); - if (listener_fd < 0) { - cerr << "Couldn't open a listener socket. Weird.\n"; - failure = true; - return; - } - - setsockopt(listener_fd,SOL_SOCKET,(SO_REUSEPORT | SO_REUSEADDR),(char*)&option,sizeof(option)); - - serv_addr.sin_family = AF_INET; - serv_addr.sin_addr.s_addr = INADDR_ANY; - serv_addr.sin_port = htons(baseport + id); - - if (bind(listener_fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) { - cerr << "ERROR: Couldn't bind to port #" << baseport + id << endl; - failure = true; - return; - } - - listen(listener_fd, 1); - } - - virtual void handle(unsigned char *data, int len, int listener) { - } - - virtual void newconn() { - } -}; - -char fnbuf[80]; -struct audio_sockin : public sockin { - int leftover; - int a_fd; - -// uint16_t buf[ABUFLEN]; -// int bufsize; - - audio_sockin(int _id) : sockin(_id, 4000) { - leftover = -1; - //bufsize = 0; - - a_fd = -1; - - if (f_saveaudio) { - sprintf(fnbuf, "%s.raw", names[id]); - a_fd = open(fnbuf, O_WRONLY | O_APPEND | O_CREAT, S_IRWXU | S_IROTH); - } - } - - virtual void handle(unsigned char *data, int len, int listener) { - int new_leftover = -1; - if (len % 2) { - new_leftover = data[len - 1]; - len--; - } - - if (leftover >= 0) { - if (a_fd >= 2) write(a_fd, &leftover, 1); - if (listener == id) write(1, &leftover, 1); - leftover = -1; - } - if (a_fd >= 2) write(a_fd, data, len); - if (listener == id) write(1, data, len); - leftover = new_leftover; - } - - // new connection: better not have an odd # output for audio! - virtual void newconn() { - leftover = -1; - } -}; - -const int IBUFLEN = 2048*1024; // in bytes - -bool displayed = false; - -struct image_sockin : public sockin { - uint8_t buf[IBUFLEN]; - int bufsize; - - image_sockin(int _id) : sockin(_id, 4100) { - bufsize = 0; - } - - void showImage(int begin, int end, int listener) { - if (f_showall || (listener == id)) { - Mat imgbuf = cv::Mat(480, 640, CV_8U, &buf[begin]); - Mat imgMat = cv::imdecode(imgbuf, CV_LOAD_IMAGE_COLOR); - - if (!imgMat.data) cerr << "reading failed\r\n"; -// cerr << "x " << imgMat.rows << ' ' << imgMat.cols << "\r\n"; - - imshow(f_showall ? names[id] : "Display Window", imgMat); -// cerr << "updated\r\n"; - displayed = true; - } - } - - virtual void handle(unsigned char *data, int len, int listener) { - int begin = -1, end = -1; - - if ((len + bufsize) > IBUFLEN) { - bufsize = 0; - } - - memcpy(&buf[bufsize], data, len); - bufsize += len; - - for (int i = 0; ((begin == -1) || (end == -1)) && (i < bufsize - 1); i++) { - // if (buf[i] == 0xff) cerr << i << ' ' << (int)buf[i + 1] << "\r\n"; - if ((buf[i] == 0xff) && (buf[i + 1] == 0xd8)) begin = i; - if ((buf[i] == 0xff) && (buf[i + 1] == 0xd9)) end = i; - } - -// cerr << "A " << bufsize << ' ' << begin << ' ' << end << "\r\n"; - - if ((begin >= 0) && (end >= 0)) { - if (begin > end) { - memmove(buf, &buf[begin], bufsize - begin); - bufsize -= begin; - } else { -// cerr << "doshow\r\n"; - showImage(begin, end, listener); - bufsize = 0; - } - } - - - } - - virtual void newconn() { - bufsize = 0; - } -}; - -sockin *s[MAX]; - -unsigned char buf[BUFLEN]; - -struct termios oldtermios; - -void sigcatch(int sig) -{ - tcsetattr(0, TCSAFLUSH, &oldtermios); - _exit(0); -} - -bool setrawkbd() -{ - // set keyboard to raw mode + unblocking - struct termios newtermios; - - if(tcgetattr(0, &oldtermios) < 0) - _exit(1); - - newtermios = oldtermios; - - newtermios.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG); - newtermios.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON); - newtermios.c_cflag &= ~(CSIZE | PARENB); - - newtermios.c_cflag |= CS8; - - newtermios.c_oflag &= ~(OPOST); - - newtermios.c_cc[VMIN] = 1; - newtermios.c_cc[VTIME] = 0; - - if(tcsetattr(0, TCSAFLUSH, &newtermios) < 0) - _exit(1); - - int opts = fcntl(0, F_GETFL); - if (opts < 0) { - cerr << "HUH? fcntl failed\n"; - return false; - } - if (fcntl(0, F_SETFL, opts | O_NONBLOCK) < 0) { - cerr << "HUH? fcntl(F_SETFL) failed\n"; - return false; - } - return true; -} - -int main(int argc, char *argv[]) -{ - int main_rv = 0; - int cur_listener = 0; - - int num_sockets = (MAX * 2); - sockin *s[num_sockets]; - - opterr = 0; - - int c; - - while ((c = getopt(argc, argv, "as")) != -1) { - switch (c) { - case 's': - f_saveaudio = true; - break; - case 'a': - f_showall = true; - break; - }; - } - - if (f_showall) { - for (int i = 0; i < MAX; i++) { - namedWindow(names[i], WINDOW_AUTOSIZE ); - } - } else { - namedWindow("Display Window", WINDOW_AUTOSIZE ); - } - - // catch signals - if (((void *)signal(SIGINT,sigcatch) < 0) || - ((void *)signal(SIGQUIT,sigcatch) < 0) || - ((void *)signal(SIGTERM,sigcatch) < 0)) { - cerr << "Couldn't set up signal catching. huh?\n"; - return(1); - } - - if (!setrawkbd()) { - goto err_exit; - } - - for (int i = 0; i < num_sockets; i+=2) { - s[i] = NULL; - } - - // init listening sockets - for (int i = 0; i < num_sockets; i+=2) { - s[i] = new audio_sockin(i / 2); - s[i+1] = new image_sockin(i / 2); - } - - if (failure) - goto err_exit; - - cls(); - - // now listen for connections and data - while (1) { - int topfd = -1; - int rv; - fd_set readfds, writefds, exceptfds; - - struct timespec t; - - t.tv_sec = 1; - t.tv_nsec = 0; - - FD_ZERO(&readfds); - FD_ZERO(&writefds); - FD_ZERO(&exceptfds); - - FD_SET(0, &readfds); - - for (int i = 0; i < num_sockets; i++) { - if (s[i]->listener_fd >= 0) { - FD_SET(s[i]->listener_fd, &readfds); - if (s[i]->listener_fd >= topfd) topfd = s[i]->listener_fd + 1; - } - if (s[i]->data_fd >= 0) { - FD_SET(s[i]->data_fd, &readfds); - if (s[i]->data_fd >= topfd) topfd = s[i]->data_fd + 1; - } - } - - waitKey(1); - rv = pselect(topfd, &readfds, &writefds, &exceptfds, &t, NULL); - if (rv == -1 && errno != EINTR) { - cerr << "ERROR: select failed\n"; - goto err_exit; - } - - if ((rv > 0) && FD_ISSET(0, &readfds)) { - unsigned char c; - - int rv = read(0, &c, 1); - - if (rv == 0) goto good_exit; - - if (rv == 1) { - int old_listener = cur_listener; - -// cerr << "Got char " << (int)c << "\r\n"; - if (c == 'q') goto good_exit; - if ((c >= '0') && (c <= '9')) { - cur_listener = c - '0'; - } - if ((c >= 'a') && (c <= 'f')) { - cur_listener = c + 10 - 'a'; - } - if ((c >= 'A') && (c <= 'F')) { - cur_listener = c + 10 - 'A'; - } - if (old_listener != cur_listener) { - cls(); - cerr << "Now listening to " << names[cur_listener] << "\r\n"; - } - } - } - - displayed = false; - for (int i = 0; (rv > 0) && (i < num_sockets); i++) { - if (!s[i]) break; - - // check for new connections - if (FD_ISSET(s[i]->listener_fd, &readfds)) { - socklen_t len = sizeof(struct sockaddr); - int newfd = accept(s[i]->listener_fd, (struct sockaddr *)&s[i]->cli_addr, &len); - if (newfd >= 0) { - if (s[i]->data_fd < 0) { - int opts = fcntl(newfd, F_GETFL); - - if (opts < 0) { - cerr << "HUH? fcntl failed\n"; - goto err_exit; - } - - if (fcntl(newfd, F_SETFL, opts | O_NONBLOCK) < 0) { - cerr << "HUH? fcntl(F_SETFL) failed\n"; - goto err_exit; - } - - s[i]->data_fd = newfd; - cerr << "New connection on " << i/2 << " " << ((i % 2) ? "video" : "audio") << "\r\n"; - s[i]->newconn(); - } else { - cerr << "HUH? new connection on socket # " << i << endl; - } - } - } - - // check for new data - if (FD_ISSET(s[i]->data_fd, &readfds)) { - int rv = read(s[i]->data_fd, buf, BUFLEN); - - if (rv == 0) { - close(s[i]->data_fd); - s[i]->data_fd = -1; - listen(s[i]->listener_fd, 1); - } else { - s[i]->handle(buf, rv, cur_listener); - } - } - } - if (displayed) waitKey(1); - }; - - - err_exit: - main_rv = 1; - - good_exit: - tcsetattr(0, TCSAFLUSH, &oldtermios); - - int sdcount = 0; - for (int i = 0; i < num_sockets; i++) { - if (s[i] && s[i]->listener_fd >= 0) { - shutdown(s[i]->listener_fd, SHUT_RDWR); - sdcount++; - } - if (s[i] && s[i]->data_fd >= 0) { - shutdown(s[i]->data_fd, SHUT_RDWR); - sdcount++; - } - } - - if (sdcount) { - cerr << "sent " << sdcount << " shutdowns\n"; - } - - for (int i = 0; i < num_sockets; i++) { - if (s[i] && s[i]->listener_fd >= 0) { - close(s[i]->listener_fd); - } - if (s[i] && s[i]->data_fd >= 0) { - close(s[i]->data_fd); - } - } - - return main_rv; -} - - diff --git a/acatcher/mkacatcher_cpp.sh b/acatcher/mkacatcher_cpp.sh index fd21af1..a39151e 100755 --- a/acatcher/mkacatcher_cpp.sh +++ b/acatcher/mkacatcher_cpp.sh @@ -1,18 +1,40 @@ #!/bin/sh +FLAGS=-g +#FLAGS=-O2 +if [ ! -f "$1" ]; then + echo "error: must specify rooms file" + exit 1 +fi + NUM=0 while read FOO; do if ! echo $FOO | grep -q ^#; then HOST="`echo $FOO | cut -d\| -f3`" MAC="`echo $FOO | cut -d\| -f1 | tr '[A-Z]' '[a-z]'`" IP="`echo $FOO | cut -d\| -f2`" - if ! echo $HOST | egrep -q "(server|spare)"; then - >&2 echo found host $HOST mac $MAC ip $IP num $NUM - HEX="`echo "obase=16; $NUM" | bc | tr '[A-Z]' '[a-z]'`" - echo "\"[$HEX] $HOST\"," - NUM=$((NUM+1)) + if ! echo $HOST | egrep -q "server"; then + if grep -q "^$HOST\$" "$1" ; then + >&2 echo found host $HOST mac $MAC ip $IP num $NUM + HEX="`echo "obase=16; $NUM" | bc | tr '[A-Z]' '[a-z]'`" + echo "\"[$HEX] $HOST\"," + NUM=$((NUM+1)) + fi elif echo $HOST | grep -q server; then >&2 echo found server at ip $IP echo $IP > SERVERIP fi fi -done < $HOME/Dropbox/CAMS > acatcher.cxx.inc +done < MASTER_LIST > acatcher.cxx.inc + +sed -e "s/_NUMHOSTS_/$NUM/" -e '/_HOSTS_/ {' -e 'r acatcher.cxx.inc' -e 'd' -e '}' < acatcher.cxx.template > acatcher.cxx + +CLANG="" +type -P "clang++" && CLANG="clang++" +type -P "clang++-3.5" && CLANG="clang++-3.5" +type -P "clang++-3.4" && CLANG="clang++-3.4" +if [ -z "$CLANG" ]; then + echo "ERROR: could not find clang" +else + echo "using $CLANG" + $CLANG $FLAGS -lopencv_core -lopencv_highgui -lopencv_imgproc -o acatcher acatcher.cxx +fi diff --git a/acatcher/mkhosts.sh b/acatcher/mkhosts.sh index 92805ed..f05c153 100755 --- a/acatcher/mkhosts.sh +++ b/acatcher/mkhosts.sh @@ -1,17 +1,24 @@ #!/bin/sh +if [ ! -f "$1" ] ; then + echo "error: must specify active rooms file" + exit 1 +fi + NUM=0 while read FOO; do if ! echo $FOO | grep -q ^#; then HOST="`echo $FOO | cut -d\| -f3`" MAC="`echo $FOO | cut -d\| -f1 | tr '[A-Z]' '[a-z]'`" IP="`echo $FOO | cut -d\| -f2`" - if ! echo $HOST | egrep -q "(server|spare)"; then - >&2 echo found host $HOST mac $MAC ip $IP num $NUM - echo "$HOST|$MAC|$IP|$NUM" - NUM=$((NUM+1)) + if ! echo $HOST | egrep -q "server"; then + if grep -q "^$HOST\$" "$1" ; then + >&2 echo found host $HOST mac $MAC ip $IP num $NUM + echo "$HOST|$MAC|$IP|$NUM" + NUM=$((NUM+1)) + fi elif echo $HOST | grep -q server; then >&2 echo found server at ip $IP echo $IP > SERVERIP fi fi -done < $HOME/Dropbox/CAMS > HOSTS +done < MASTER_LIST > HOSTS diff --git a/acatcher/provision_streamers.sh b/acatcher/provision_streamers.sh index 21bd1a5..7779b0a 100755 --- a/acatcher/provision_streamers.sh +++ b/acatcher/provision_streamers.sh @@ -1,19 +1,17 @@ #!/bin/sh -NUM=0 -while read FOO; do - HOST="`echo $FOO | cut -d\| -f1`" - MAC="`echo $FOO | cut -d\| -f2 | tr '[A-Z]' '[a-z]'`" - IP="`echo $FOO | cut -d\| -f3`" - if ! echo $HOST | egrep -q "(server|spare)"; then - >&2 echo provisining host $HOST mac $MAC ip $IP num $NUM - ssh pi@$HOST "if [ ! -d \$HOME/.ssh ]; then mkdir \$HOME/.ssh; fi; echo `cat $HOME/.ssh/id_rsa.pub` >> \$HOME/.ssh/authorized_keys; chmod 700 \$HOME/.ssh; chmod 644 \$HOME/.ssh/authorized_keys" - for FILE in HOSTS SERVERIP stream.sh set_hostname.sh v4lcap.c; do scp $FILE pi@$HOST:$FILE; done - ssh pi@$HOST "make v4lcap" - ssh pi@$HOST "cd \$HOME && bash set_hostname.sh" - ssh pi@$HOST "sudo reboot" - NUM=$((NUM+1)) - elif echo $HOST | grep -q server; then - >&2 echo found server at ip $IP - echo $IP > SERVERIP - fi -done < HOSTS +if [ ! -f "$1" ]; then + echo "error: must supply rooms list" + exit 1 +fi + +./mkhosts.sh "$1" +./mkacatcher_cpp.sh "$1" + +for HOST in `cat "$1"`; do + >&2 echo "provisioning host $HOST" + ssh pi@$HOST "if [ ! -d \$HOME/.ssh ]; then mkdir \$HOME/.ssh; fi; echo `cat $HOME/.ssh/id_rsa.pub` >> \$HOME/.ssh/authorized_keys; chmod 700 \$HOME/.ssh; chmod 644 \$HOME/.ssh/authorized_keys" + for FILE in HOSTS SERVERIP stream.sh set_hostname.sh v4lcap.c; do scp $FILE pi@$HOST:$FILE; done + ssh pi@$HOST "make v4lcap" + ssh pi@$HOST "cd \$HOME && bash set_hostname.sh" + ssh pi@$HOST "sudo reboot" +done diff --git a/acatcher/start_streamers.sh b/acatcher/start_streamers.sh index 04197b9..00212f0 100755 --- a/acatcher/start_streamers.sh +++ b/acatcher/start_streamers.sh @@ -1,17 +1,11 @@ #!/bin/sh +if [ ! -f "$1" ]; then + echo "error: must specify rooms file" + exit 1 +fi NUM=0 -while read FOO; do - if ! echo $FOO | grep -q ^#; then - HOST="`echo $FOO | cut -d\| -f3`" - MAC="`echo $FOO | cut -d\| -f1 | tr '[A-Z]' '[a-z]'`" - IP="`echo $FOO | cut -d\| -f2`" - if ! echo $HOST | egrep -q "(server|spare)"; then - >&2 echo starting up host $HOST mac $MAC ip $IP num $NUM - ssh pi@$HOST "screen -dm bash stream.sh" - NUM=$((NUM+1)) - elif echo $HOST | grep -q server; then - >&2 echo found server at ip $IP - echo $IP > SERVERIP - fi - fi -done < $HOME/Dropbox/CAMS +for HOST in `cat "$1"`; do + >&2 echo starting up host $HOST + ssh pi@$HOST "screen -dm bash stream.sh" + NUM=$((NUM+1)) +done diff --git a/acatcher/stop_streamers.sh b/acatcher/stop_streamers.sh index 823b917..625e757 100755 --- a/acatcher/stop_streamers.sh +++ b/acatcher/stop_streamers.sh @@ -1,17 +1,10 @@ #!/bin/sh +if [ ! -f "$1" ]; then + echo "error: must specify rooms file" + exit 1 +fi NUM=0 -while read FOO; do - if ! echo $FOO | grep -q ^#; then - HOST="`echo $FOO | cut -d\| -f3`" - MAC="`echo $FOO | cut -d\| -f1 | tr '[A-Z]' '[a-z]'`" - IP="`echo $FOO | cut -d\| -f2`" - if ! echo $HOST | egrep -q "(server|spare)"; then - >&2 echo killing host $HOST mac $MAC ip $IP num $NUM - ssh pi@$HOST "screen -X quit" - NUM=$((NUM+1)) - elif echo $HOST | grep -q server; then - >&2 echo found server at ip $IP - echo $IP > SERVERIP - fi - fi -done < $HOME/Dropbox/CAMS +for HOST in `cat "$1"`; do + >&2 echo stopping host $HOST + ssh pi@$HOST "screen -X quit" +done