linux - conditionally replacing number with word -
i using python script detect connected devices in local network every 2 minutes - saving output in file (i save last number of ip).
this code:
import os os.system('for ip in $(seq 1 10); ping -c 1 192.168.1.$ip>/dev/null; ' '[ $? -eq 0 ] && echo "$ip" || : ; ' 'done > /home/pi/desktop/network/logs/loglocal.txt')
the output ist example:
1 2 4 7
my question if possible replace number 7 through word? if device 7 found programm writes "seven" not 7 in file.
thanks help!
the following script job:
# note can use `{a..b}` instead of `seq` ip in {1..10} ; # no need execute command , check it's # return value. can in 1 line if ping -c 1 192.168.1.$ip > /dev/null ; # check `7` if [ "$ip" = "7" ] ; echo "seven" else if [ "$ip" = 5 ] ; echo "five" # ... , on else echo "$ip" fi fi done > output.txt
Comments
Post a Comment