First, apologies for what I know is an extremely noob question. I'm running a jail on my FreeNAS box that for some unknown reason loses its internet connection periodically. Manually restarting the jail fixes the issue. I'm trying to write a script I can call via cron to check the status of the jail and restart it automatically if need be. Here's what I have for the script:
In this example, the jail's name is "myjail." When the number of connections drops to zero, that's when I know it needs to be restarted. When I run this script, I get this output:
Something's clearly not right with my grep command, but I just don't know what it is. I've searched around and haven't really been able to figure out what I'm doing wrong. Any help would be greatly appreciated.
Code:
#!/bin/bash # MyJail Checker mj_con_string='Current IPv4 Connections: ' mj_status=$(/usr/local/bin/warden details myjail | grep -i "$mj_con_string[0-9]\+") mj_con_num="${mj_status//$mj_con_string}" if [ "$mj_con_num" = "0" ]; then echo restarting myjail /usr/local/bin/warden stop myjail && /usr/local/bin/warden start myjail else echo myjail looks fine fi
In this example, the jail's name is "myjail." When the number of connections drops to zero, that's when I know it needs to be restarted. When I run this script, I get this output:
Code:
Usage: grep [OPTION]... PATTERN ... Try `grep --help' for more information. /usr/bin/mj_check: line 8: Current IPv4 Connections: [0-9]\+: command not found myjail looks fine
Something's clearly not right with my grep command, but I just don't know what it is. I've searched around and haven't really been able to figure out what I'm doing wrong. Any help would be greatly appreciated.