#! /bin/bash # script pings defined IP and writes log with date-time . /usr/src/m2/framework/bash_functions.sh . /usr/src/m2/framework/settings.sh # ---- VARS ----- VERSION="1.0.2" SCRIPT_NAME="Ping with logging" # ---- MAIN ----- report "" 7 k_start if ! k_we_are_inside_screen; then report "It is strongly advised to run this script from the 'screen' program. To do so - just run command 'screen' and launch the script again as usual" 2 exit 1 fi if [ -z $1 ]; then report "Enter IP as an argument to the script" exit 1 fi IP=$1 LOG="/var/log/m2/ping$IP.log" mv $LOG $LOG-backup_`date '+%Y-%m-%d_%H:%M:%S'` > /dev/null 2>&1 report "Log file: $LOG" 3 report "Starting pinging $IP. Stop with CTRL+Z" 3 ping -i 5 $IP | while read line; do echo `date '+%Y-%m-%d %H:%M:%S'` - $line; done > $LOG