So I'm writing some scripts to automate pushing keys for SSH to ease deployment of new linux boxes (these are modems running an embedded linux). So far I have a database that stores the info about the server, a script that will push the keys and report if they are successful (which works well), and an expect script that runs the first script using the IP address that gets passed to it as an argument. What I have halfway done is a script that can run as a cron job and will get the IP address of a box that hasn't had keys pushed to it and pass that as an argument to the expect script, the problem is it doesn't stop when all records in the DB have been hit and had the key_status updated, and I get the following error: line 26: [: =: unary operator expected
A sample of the code is below:
Any help or tips you could point me to would be appreciated.
edit: fixed the "line 26: [: =: unary operator expected", was missing set of quotes around $result on line 26.
A sample of the code is below:
Code:
1 #/bin/bash
2
3
4 function get_ip {
5 ipaddr=$(mysql pkg_deploy -B -N -e "select addr from modem_status where key_status != 'downloaded' and pkg_status != 'downloaded' limit 1;")
6 }
7
8 function update_key_status_success {
9 mysql pkg_deploy -e "UPDATE modem_status SET key_status = 'downloaded' where addr = '$ipaddr';"
10 }
11
12 function push_keys {
13 result=$(/root/deploy_keys.sh $ipaddr|grep successfully|awk '{printf $6}')
14 }
15 function update_key_status_failed {
16 mysql pkg_deploy -e "UPDATE modem_status SET key_status = 'failed' where addr = '$ipaddr';"
17 }
18 function get_next_ip {
19 ipaddr=$(mysql pkg_deploy -B -N -e "select addr from modem_status where key_status = '' and pkg_status != 'downloaded' LIMIT 1;")
20 }
21
22 while [ -n $ipaddr ]
23 do
24 get_ip
25 push_keys
26 if [ $result = "successfully" ]
27 then update_key_status_success
28 get_next_ip
29 else
30 update_key_status_failed
31 get_next_ip
32 fi
33 continue
34 done
Any help or tips you could point me to would be appreciated.
edit: fixed the "line 26: [: =: unary operator expected", was missing set of quotes around $result on line 26.