shell scripting
Marius Gedminas
marius at pov.lt
Mon Nov 11 10:48:01 UTC 2013
On Sat, Nov 09, 2013 at 05:23:19PM +0100, pluto mars wrote:
> I need some help with shell scripting (/bin/sh) in ubuntu.
>
> In a shell script I want to turn down an interface, say eth0 and then turn
> it up.
If you told us why you want to write this shell script, we might be able
to come up with a better way to solve whatever problem you're trying to
solve.
> 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.
> So something like "if ( eth0 not is up ) { sleep 1 }. But how do I do this
> in shell scripting ?
Do you use DHCP? If so, it may not be sufficient to wait for the
interface to be up, you probably also want for a valid DHCP lease.
The simplest way I can think of is to wait until the default route gets
configured:
while ! ip r | grep -q default; do
sleep 1
done
> 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.
Why would syslog not be up? Upstart ensures rsyslog will be present via
/etc/init/rsyslog.conf.
You can check for its presence and with something like
if [ -z "$(pidof -s rsyslogd)" ]; then
service rsyslogd start
fi
or just issue the 'service rsyslogd start' unconditionally, it does
nothing if rsyslogd is already running.
Marius Gedminas
--
Gates' Law: Every 18 months, the speed of software halves.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20131111/cea655b2/attachment.sig>
More information about the ubuntu-users
mailing list