#!/bin/bash CFGNAME=journald.conf ## This script takes as a a first argument the directory containing ## the systemd journal configuration file (journald.conf). According ## to the value of the second argument, the script either save the ## current journald.conf file and swith on systemd forwarding to ## syslog; or restore the back-up file if [ $# -ne 2 ]; then echo "rsyslog_switchfwd should be called with 2 arguments" exit 1 fi JNLDIR=$1 SYSFWD=$2 JNLFILE=$1/$CFGNAME JNLSAVE=$JNLFILE.rsyslog #exit if file is not found if [ ! -r $JNLFILE ]; then echo "systemd journal configuration file not found!" exit 1 fi case $SYSFWD in yes | 1 | on) #abort if it already exists if [ -r $JNLSAVE ]; then echo "journal configuration file already modified!" exit 1 fi #save the current file mv $JNLFILE $JNLSAVE #edit the new cp $JNLSAVE $JNLFILE echo "switching on syslog forwarding in: $JNLFILE" sed -i 's|#ForwardToSyslog=no|ForwardToSyslog=yes|g' $JNLFILE ;; no | 0 | off) #abort if it does not exist if [ ! -r $JNLSAVE ]; then echo "saved journal configuration file not found!" exit 1 fi echo "restoring original journal configuration from $JNLSAVE" mv $JNLSAVE $JNLFILE ;; *) echo "invalid argument" exit 1 esac exit 0