Ubuntu 10.10 bash script containing the rules for NAT?

Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike

In explanation the most useful Topeka set up a parallel (balanced) pair PPPoE connections with two local providers.

Author topic suggested two scripts: the first to specify routes and masquerading (NAT for Internet sharing to the rest of the local computers), the second to test the connection with pings then one, then the other interface and, appropriate, (re)assignment for the gateways (depending on the passage of the pings is enabled the gateway of the first provider, the second or both at once balanced). The second script is in its very early simply calls the first. Themselves scripts entirely possible to look into that topic.

Everything turned out perfectly. Work available, distributed in a LAN.

But the idyll lasted until I handles in the console run: # /etc/balance/check.sh

And the weirdness started after quite a natural step. To up itself after a reboot, I added in crontab for root:
@reboot /etc/balance/check.sh

After you download the system check and see:
# ps ax | grep che
1261 ? Ss 0:00 /bin/sh -c /etc/balance/check.sh
1262 ? S 0:00 /bin/bash /etc/balance/check.sh

That is how the script would start.

And the Internet on the machine (and on ppp1 and ppp2 — all good) but on eth0 (to LAN) — it does not sound.

At the same time, if I do it again manually in the console that seemed to have made the cron:
# /etc/balance/check.sh

And I see this message:
RTNETLINK answers: File exists

And then starts output of the script ("Both channels", etc.) and, most importantly, at eth0 there is the Internet.

Suggested that the script is executed too early (for example, mascarading still nothing at the moment of his execution), set this in crontab:
5 23 * * * /etc/balance/check.sh

And restarted the car almost exactly 23 hours. Output redirected to a file. I looked in 23:10 — log script to write in time started, i.e. start the script on time, but the Internet does not sound. After starting manually in the console — all again apprx.

Tell me, please, what is the magic?

And, ideally, tell me the correct way to start all this stuff at boot and automatically restart if a script suddenly when something will die.

Thank you.

P. S. I Publish this question in addition to the comments in the topic, as the author of a topic on Habre a couple of days did not appear (and be notified of new comments the top level comes only to the author).

P. P. S. I asked this question on habré and not on any forum, because it is valuable in my situation the manual I also found only on Habre, but not on any forum.
by | 5 views

6 Answers

0 like 0 dislike
Specify the full path to all used binaries: /sbin/ip, /sbin/iptables , etc.
cron, carrying the team does not pass the PATH environment variable, or passes it a stripped-down, not containing /sbin/.
0 like 0 dislike
In cron run the script using sudo make
sudo /etc/balance/check.sh
right here in CZK
0 like 0 dislike
try to add in the beginning of the script:
sleep 120
(any other time)
the service had to restart, and then run the script.
0 like 0 dislike
Try more strerr somewhere to redirect. The idea is that if the crown skrite fails, and the message is nowhere to be output, then the script will stop. redirected to stderr command 2>, for example:
check.sh >/dev/null 2>/dev/null
0 like 0 dislike
The matter may be that at the time of the execution of the script you have may not be the network on the machine.
To debug put in the shabangu !/bin/sh -x and redirect the output to a log, as advised by someone earlier.
If you are correct is to run the script init-script after networking.
0 like 0 dislike
It is necessary to add sudo before calling the script from crontab.
Or specify the absolute path /sbin/ip and /sbin/iptables in scripts.
Because the environment variable PATH, it seems, does not pass when running crown /sbin.
A huge thank you to everyone who helped here to resolve the problem.

Related questions

0 like 0 dislike
4 answers
asked Mar 20, 2019 by kolobob
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
asked May 20, 2019 by HighwayToCode
110,608 questions
257,186 answers
27,959 users