The three lines can run.
debian8@hwy:~$ trafficlog="/var/log/traffic.log"
debian8@hwy:~$ echo `date "+%Y-%m-%d %H:%M:%S "` | sudo tee -a $trafficlog
2017-02-04 21:20:41
debian8@hwy:~$ sudo iptables -v -L INPUT |grep Chain | sudo tee -a $trafficlog
Chain INPUT (policy ACCEPT 122 packets, 28381 bytes)
Let me check it.
debian8@hwy:~$ cat /var/log/traffic.log
2017-02-04 21:20:41
Chain INPUT (policy ACCEPT 122 packets, 28381 bytes)
Now to make it run at the runlevel6 on my debian8.
sudo vim /etc/init.d/K99trafficLog.sh
#!/bin/bash
trafficlog="/var/log/traffic.log"
echo `date "+%Y-%m-%d %H:%M:%S "` | sudo tee -a $trafficlog
sudo iptables -v -L INPUT |grep Chain | sudo tee -a $trafficlog
sudo chmod +x /etc/init.d/K99trafficLog.sh
sudo ln -s /etc/init.d/K99trafficLog.sh /etc/rc6.d/K99trafficLog
Now to test it.
echo "" | sudo tee /var/log/traffic.log
Then to reboot to verify.
sudo cat /var/log/traffic.log
It is unlucky that nothing written into /var/log/traffic.log,why?
echo \
...`` makes no sense at all. – michas Feb 04 '17 at 13:42