shell scripting

Hal Burgiss hal at burgiss.net
Sat Nov 9 23:06:37 UTC 2013


On Sat, Nov 9, 2013 at 11:23 AM, pluto mars <plutomars955 at gmail.com> wrote:

> In a shell script I want to turn down an interface, say eth0 and then turn
> it up.
>  So something like
>
> ifdown eth0
> ifup eth0
>
> But what I want in my shell script is to check and wait till eth0 is up
> and then start doing something next in my shell script.
>

untested pseudo code ...

function is_up () {
  IFACE=eth0
    if ! ifconfig | grep $IFACE >/dev/null 2>&1 ||\
      ! ifconfig $IFACE | grep UP >/dev/null 2>&1; then
         # maybe do additional network test here like ping google.com to
see if interface is up and connection is usable
          return 1
   fi
   return 0
}

while ! is_up; do
  # probably need timeout logic here, ie count loops, exit on error
  sleep 1;
done



> So something like "if ( eth0 not is up ) { sleep 1 }. But how do I do this
> in shell scripting ?
>
> And then also I want something similar for checking if syslog process is
> up or not. Because actually I am writing syslog through that interface to
> another computer. So I want to check if eth0 is up. If up, check if syslog
> process is up, if not start, if yes, write something to syslog.
>
>
if ps aux |grep syslogd |grep -v grep > /dev/null .... blah.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20131109/7581dcff/attachment.html>


More information about the ubuntu-users mailing list