Answer the question
In order to leave comments, you need to log in
Ubuntu 10.10 bash script containing rules for NAT?
Hello.
Based on the most useful topic , I configured myself in parallel (with balancing) a pair of PPPoE connections with two local providers.
The author of the topic proposed two scripts: the first one for setting routes and masquerading (NAT for distributing the Internet to other local computers), the second one for checking the connection by pings either on one or another interface and, correspondingly, (re)setting gateways (depending on the passage pings, the gateway of the first provider, the second one, or both with balancing is turned on). The second script at its very beginning simply calls the first one. The scripts themselves can be viewed in their entirety in that topic .
Everything worked out great. Available channels work, the Internet is distributed to the local area.
But the idyll continued while I ran the handles in the console: # /etc/balance/check.sh
And oddities began after a completely natural step. To make everything rise by itself after the reboot, I added to the crontab for root: @reboot /etc/balance/check.sh
After the system boots, I check and see:
# ps ax | grep che<br/>
1261 ? Ss 0:00 /bin/sh -c /etc/balance/check.sh<br/>
1262 ? S 0:00 /bin/bash /etc/balance/check.sh
# /etc/balance/check.sh
RTNETLINK answers: File exists
5 23 * * * /etc/balance/check.sh
Answer the question
In order to leave comments, you need to log in
Write the full path to all used binaries: /sbin/ip
, /sbin/iptables
etc.
cron, when executing commands, does not pass the PATH environment variable or passes it a truncated one that does not contain /sbin/
.
Run the script in cron using sudo
sudo /etc/balance/check.sh
directly like this in cron
Try to redirect strerr somewhere else. In theory, if an error occurs in the cron-skrit, and there is nowhere to output the message, the script will stop. stderr is redirected with the 2> command, for example:
check.sh >/dev/null 2>/dev/null
The point may be that at the time the script is executed, you still may not have a network on the machine.
To debug, put !/bin/sh -x in the shaban and redirect the output to the log, as the friend advised above.
If justified, run the script with an init script after networking.
So.
You must either add sudo
before calling the script from the crontab.
Or write absolute paths /sbin/ip
in /sbin/iptables
scripts.
Because the environment variable PATH
doesn't seem to be passed to cron when running /sbin
.
Many thanks to everyone who helped here to solve the problem.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question