In this post I would like to replace all <embed> HTML tags in a HTML file with a <strong> tag.
# sed -e 's/<embed[^>]*>/<strong>/g' filename.html > newfile.html
And if you would like to remove the <embed> tag altogether
# sed -e 's/<embed[^>]*>//g' filename.html > newfile.html
To remove all HTML tags in a file
# sed -e 's/<[^>]*>//g' filename.html > newfile.html
The result file newfile.html is now without any < HTML tags >.
Tags: html, regexp, replace, sed
Posted by Hans-Henry Jakobsen
This is a simple bash script that is run by crontab every 5 minutes on a linux box.
It e-mails me the new address when a change of IP address is detected.
The script (ipchangemail.sh)
#!/bin/bash
# Check if IP-address has changed. If a change has occured, mail me the new address
# Add the following line to crontab if you would like it to be run every 5 minutes:
# */5 * * * * ./ipchangemail.sh
# The network interface I want to monitor
NET_INTERFACE=eth0
# File to keep the latest IP address
IP_FILE=myip.txt
# Mail to this address when a change occur
MAILTO=mail@example.com
# Read the previous IP address from file
source $IP_FILE
CURRENT_IP=`/sbin/ifconfig $NET_INTERFACE | sed -n "/inet addr:.*255.255.25[0-5].[0-9]/{s/.*inet addr://; s/ .*//; p}"`
if [ "$CURRENT_IP" != "$OLD_IP" ]
then
# Send email about address change
`echo "New IP address detected: $CURRENT_IP" | mail -s "New IP address" $MAILTO`
# Write new address to file
`echo "OLD_IP=$CURRENT_IP" > $IP_FILE`
fi
The script can be downloaded here.
Tags: bash, ifconfig, mail, sed
Posted by Hans-Henry Jakobsen
This is a bash oneliner to show Apache web connections pr hour. It lists up the IPs that has accessed your webserver and the amount og accesses.
# cat /var/log/apache2/access_log_pario.no | grep "21/Jan/2008:.." | awk {' print $4":"$1 '} | sed 's/\[//g' | awk -F : {' print $1":"$2"\t\t"$5 '} | sort | uniq -c
Example output
37 21/Jan/2008:00 192.168.0.10
This shows that I had 37 hits from 00:00 – 01:00 in 20th February 2008.
Tags: Apache, awk, bash, grep, sed
Posted by Hans-Henry Jakobsen
This is a great page with som nice bash scripts describing how to remove unwanted modules from your kernel.
Tags: bash, cut, grep, kernel, lsmod, modinfo, sed, xargs
Posted by Hans-Henry Jakobsen
#!/bin/bash
# nslookup-scan of IP-range
# It's possible to add more networks separated with space
NETS="192.168.0"
IPRange="1 254"
for NET in $NETS; do
for n in $(seq $IPRange); do
ADDR=${NET}.${n}
echo "${ADDR},`nslookup ${ADDR} | awk -F "=" '{ print $2 }'|sed 's/^[ t]*//' | sed '/^$/d' | |sed 's/.$//'`"
done
done
Result
192.168.0.1,cba.infra.no 192.168.0.2,bca.infra.no 192.168.0.3,abc.infra.no 192.168.0.4, 192.168.0.5, 192.168.0.6, 192.168.0.7, 192.168.0.8,
Tags: awk, bash, nslookup, sed
Posted by Hans-Henry Jakobsen