Archive for the ‘ Bash ’ Category

firewall-cmd, xargs and formatting

firewall-cmd –direct –get-all-rules | xargs -n1 echo ipv4 nat PREROUTING 1 ! –src 172.30.25.0/24 –dst 10.0.25.1 -p tcp –dport 3050 -j DNAT –to 172.30.25.168:3050 -m comment –comment LVS -> server If you finished with such unformatted text, you can use the parameter -i [root@db3 ~]# firewall-cmd –direct –get-all-rules | grep “168\|.25.1\s”| head -n 2 | […]

Read more...

How to log errors of all scripts executed via cron to one file?

To achieve such feature I prepared mix which is to be used in both script and cron The example: crontab -l CRON_ERR=/var/log/overseer.log * * * * * YourScript.sh 2>>$CRON_ERR || echo “[`date`] YourScript.sh” >>$CRON_ERR 2>&1 As I have already mentioned you have to modify your script either #!/bin/bash set -E GLOBAL_ERR=0 trap “GLOBAL_ERR=127” ERR [… […]

Read more...