Oneliner to rename files/directories. It converts ” ” into “_” and the characters to lower-case.
$> perl -e 'while(< *>) { $old=$_; s/ +/_/g; rename($old,lc($_)); }'
To limit it to a single filetype use it this way and replace ”.doc” with whatever you like.
$> perl -e 'while(< *.doc>) { $old=$_; s/ +/_/g; rename($old,lc($_)); }'
Tags: perl
Posted by Hans-Henry Jakobsen
A easy way to get information about shutdowns and reboots is to run the command
last reboot
or
last -x | grep down
Tags: last
Posted by Hans-Henry Jakobsen
If you have shell access to your webserver this script can be used to upgrade your WordPress installation to the latest version quickly. Always remeber to backup your database and installation files before running it!
Do change the bold text to reflect your WordPress Internet address before you run the script.
#!/bin/bash
CURDIR=$(pwd)
SITE="http://yoursite.com/wordpress"
echo Updating WordPress located in $CURDIR
echo 1. Downloading latest WordPress install file.
wget -q http://wordpress.org/latest.tar.gz
echo 2. Unpacking downloaded file.
tar zxf latest.tar.gz
cd wordpress/
echo 3. Replacing old files with the unpacked ones.
tar cf - . | (cd $CURDIR; tar xf -)
echo 4. Update the WordPress installation.
wget -q -O - ${SITE}/wp-admin/upgrade.php?step=1> /dev/null
echo 5. Removing the WordPress file downloaded recently.
rm -f ../latest.tar.gz
echo 6. WordPress is now upgraded.
Tags: bash, shell, upgrade, Wordpress
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
This is a simple oneliner to replace words inline using perl :)
# for i in `find ./ -name foo` ; { perl -p -i -e “s/oldword/newword/g” $i ;}
You’ll need bash and perl.
Posted by Hans-Henry Jakobsen