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
By doing the following you can deny certain daemons to be available in specified hours by using hosts.allow and hosts.deny.
In my example I will be using the vsftpd daemon by adding
tcp_wrapper=YES
in /etc/vsftpd.conf.
Make sure that your private network has access all the time by adding this in /etc/hosts.allow
vsftpd: 192.168.0.
Enables access to the whole subnet.
Next you create a /etc/cron.d/vsftpd file
0 16 * * 1-5 root perl -i -p -e s/innhold//ig /etc/hosts.deny 0 8 * * 1-5 root echo "vsfdpt:ALL >> /etc/hosts.deny
Reload the cron daemon and you’re good to go.
The above example will deny all addresses, except those specified in hosts.allow, between 08:00 and 16:00 Monday to Friday and clear the block at other times.
Posted by Hans-Henry Jakobsen