Есть скрипт, который запускается по заданию в cron (root 'овый).
В том числе в этом скрипте есть такие строчки
var1=$(command1 | command2) <br>
echo "text text "$var1"" >> /var/log/file.log<br>
Так вот, если скрипт был запущен через CRON задачу, то «echo» в file.log записывается не полностью «text text», без переменной.
Если скрипт запустить ручками, то «echo» записывается в file.log полностью: «text text Result_of_VAR1»
Сам скрипт#! /bin/bash<br>
ISP2=eth1<br>
ISP1=eth2<br>
gw2=X.X.X.X # Gateway 1, preferred<br>
gw1=X.X.X.X # Gateway 2, backup<br>
config_2="/re/config.boot_eth1"<br>
config_1="/re/config.boot_eth2"<br>
ping_ip=8.8.8.8<br>
ping_ip2=8.8.4.4<br>
hold_preferred=YES <br>
vyatta_cfg=/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper<br>
function check_inet<br>
{<br>
/bin/ping -c 3 $ping_ip >> /dev/null 2>/dev/null<br>
echo $?<br>
}<br>
status=$(check_inet)<br>
current_gw=$(route -n 2>/dev/null | /bin/grep 0.0.0.0 | /bin/grep UG | awk '{ print $2 }')<br>
echo "[`date`] Detecting current gateway..." >> /var/log/switch_IPS.log<br>
echo "[`date`] Current default gateway is "$current_gw"" >> /var/log/switch_IPS.log<br>
echo "[`date`] Checking Internet connection..." >> /var/log/switch_IPS.log<br>
check_inet<br>
if [ $status -eq 0 -a "$current_gw" == "$gw1" ]; then<br>
echo "[`date`] Internet connection is OK, exiting." >> /var/log/switch_IPS.log<br>
exit<br>
elif [ $status -eq 0 -a "$current_gw" == "$gw2" ]; then<br>
echo "[`date`] You are using a working backup line." >> /var/log/switch_IPS.log<br>
if [ "$hold_preferred" == "YES" ]; then<br>
echo "[`date`] Checking primary line..." >> /var/log/switch_IPS.log<br>
/bin/ping -c 3 -I $ISP1 $ping_ip2 >> /dev/null<br>
if [ $? -eq 0 ]; then<br>
echo "[`date`] Primary line is online. Switching back." >> /var/log/switch_IPS.log<br>
/usr/bin/tail -n30 /var/log/switch_IPS.log | mail --no-user-config -s "ETH2 on Vyatta-HO is Up Again: Switching back to main interfaces: ISP1" user@gmail.com > /dev/null 2> /dev/null<br>
$vyatta_cfg begin<br>
$vyatta_cfg load $config_1<br>
$vyatta_cfg commit<br>
$vyatta_cfg save<br>
/sbin/ip route del $ping_ip2 >> /dev/null<br>
exit<br>
else<br>
echo "[`date`] Primary line is offline. Staying on backup line." >> /var/log/switch_IPS.log<br>
exit<br>
fi<br>
fi<br>
elif [ $status -ne 0 ]; then<br>
if [ "$current_gw" == "$gw1" ]; then<br>
echo "[`date`] Primary line is faulty !ERROR!. Switching to backup line." >> /var/log/switch_IPS.log<br>
/usr/bin/tail -n30 /var/log/switch_IPS.log | mail --no-user-config -s "ETH2 on Vyatta-HO is Down: Switching to backup interface: ISP2" user1@gmail.com > /dev/null 2> /dev/null<br>
$vyatta_cfg begin<br>
$vyatta_cfg load $config_2<br>
$vyatta_cfg commit<br>
$vyatta_cfg save<br>
/sbin/ip route add $ping_ip2 via $gw1 >> /dev/null<br>
exit<br>
if [ $(check_inet) -eq 0 ]; then<br>
echo "[`date`] Backup line is operable." >> /var/log/switch_IPS.log<br>
else<br>
echo "[`date`] Backup line is *NOT* operable !ERROR!. Call your ISP." >> /var/log/switch_IPS.log<br>
echo "[`date`] Switching back to primary line." >> /var/log/switch_IPS.log<br>
$vyatta_cfg begin<br>
$vyatta_cfg load $config_2<br>
$vyatta_cfg commit<br>
$vyatta_cfg save<br>
exit<br>
fi<br>
elif [ "$current_gw" == "$gw2" ]; then<br>
echo "[`date`] Backup line is faulty !ERROR!. Switching to primary line." >> /var/log/switch_IPS.log<br>
/usr/bin/tail -n30 /var/log/switch_IPS.log | mail --no-user-config -s "ETH3 on Vyatta-HO is Down: Switching to interface: ISP1" user1@gmail.com > /dev/null 2> /dev/null<br>
$vyatta_cfg begin<br>
$vyatta_cfg load $config_1<br>
$vyatta_cfg commit<br>
$vyatta_cfg save<br>
exit<br>
if [ $(check_inet) -eq 0 ]; then<br>
echo "[`date`] Primary line is operable." >> /var/log/switch_IPS.log<br>
else<br>
echo "[`date`] Primary line is *NOT* operable !ERROR!. Call your ISP." >> /var/log/switch_IPS.log<br>
echo "[`date`] Switching back to backup line." >> /var/log/switch_IPS.log<br>
$vyatta_cfg begin<br>
$vyatta_cfg load $config_2<br>
$vyatta_cfg commit<br>
$vyatta_cfg save<br>
exit<br>
fi<br>
fi<br>
fi<br>