This is a simple bash script I whipped together to make som custom changes on our linux installations, it can be used as a kickstart post-configuration file for RedHat RHEL4 and RHEL5 installations.
#!/bin/bash # Enable daily updates of the locate database perl -pi -e 's/DAILY_UPDATE=no/DAILY_UPDATE=yes/' /etc/updatedb.conf # Customize login banners echo "Authorized users only. All activity may be monitored and reported" >> /etc/motd echo "Authorized users only. All activity may be monitored and reported" >> /etc/issue.net # Disable SELinux (this should be changed back when any problems with it has been fixed) #perl -pi -e 's/^SELINUX=.*$/SELINUX=Disabled/' /etc/selinux/config # Configure tcp wrappers host access to allow only ssh access cat <> /etc/hosts.allow ALL:localhost sshd:ALL EOF cat < > /etc/hosts.deny ALL:ALL EOF
Posted by Hans-Henry Jakobsen
This is a simple bash script to restart a dead daemon, in this example I’ll use apache
#!/bin/bash
# Automatically restart httpd if it dies
netstat -ln | grep ":80 " | wc -l | awk '{if ($1 == 0) system("/etc/init.d/httpd restart") }'
Tags: bash
Posted by Hans-Henry Jakobsen
This is a simple bash script to rename all JPG file extensions to JPEG, it works recursively and takes subfolders also.
#!/bin/bash
function rename_extension
{
#change all .jpg to .jpeg
for file in $1/*.jpg; do
mv $file $1/`basename $file .jpg`.jpeg;
echo $file;
done;
# recurse directories
for d in $1/*; do
if test -d $d; then
rename_extension $d;
fi;
done;
}
dir=`pwd`;
rename_extension $dir;
Posted by Hans-Henry Jakobsen
Today I’ve setup a cold backup routine to backup my Zimba installation running on my Debian (Etch) 4.0 server that is in full production now for my private domains. This is a slightly modified backup script for the Open Source Edition of Zimbra from the Zimbra Wiki. Please note that the script does a full backup every time it’s being run!
#!/bin/bash # Zimbra Backup Script # Requires sftp to run # This script is intended to run from the crontab as root # Free to use and free of any warranty! Daniel W. Martin, 9 Sept 2007 # Live sync before stopping Zimbra to minimize sync time with the services down # Comment out the following line if you want to try single cold-sync only rsync -avHK --delete /opt/zimbra/ /backup/zimbra # which is the same as: /opt/zimbra /backup # Including --delete option gets rid of files in the dest folder that don't exist at the src # this prevents logfile/extraneous bloat from building up overtime. # Stop Zimbra Services sudo -u zimbra /opt/zimbra/bin/zmcontrol stop sleep 40 # Sync to backup directory rsync -avHK --delete /opt/zimbra/ /backup/zimbra # Restart Zimbra Services sudo -u zimbra /opt/zimbra/bin/zmcontrol start # Create a txt file in the backup directory that'll contain the current Zimbra # server version. Handy for knowing what version of Zimbra a backup can be restored to. sudo -u zimbra zmcontrol -v > /backup/zimbra/conf/zimbra_version.txt # or examine your /opt/zimbra/.install_history # Create archive of backed-up directory for offsite transfer # cd /backup/zimbra ZimbraVersion=zimbraBackup-zcs-5.0.1_GA_1902.DEBIAN4.0.20080109200914 tar -zcf /backup/$ZimbraVersion-$(date +"%Y-%m-%d").tgz -C /backup/zimbra . # Transfer file to backup server using passwordless sftp scp zimbraBackup-zcs-5.0.1_GA_1902.DEBIAN4.0.20080109200914-$(date +"%Y-%m-%d").tgz username@example.com:/path/to/backupfolder/
I’ve described passwordless ssh/sftp session in a earlier post so I won’t describe the last line of the backup script.
Tags: backup, bash, Debian, sftp, tar., Zimbra
Posted by Hans-Henry Jakobsen
As far as I know Debian doesn’t have any defined way to save your iptables rules.
I’ve done it this way:
First I’ve made my iptables rules and made sure they work.
Second is to save those rules to a configuration file
iptables-save > /root/scripts/iptables.save
I always try to save my custom scripts and required files in the /root/scripts/ folder.
Now make a script that loads the iptables rules at reboot
echo "#!/bin/bash" > /etc/network/if-up.d/iptables echo "iptables-restore < /root/scripts/iptables.save > >> /etc/network/if-up.d/iptables chmod +x /etc/network/if-up.d/iptables
This has been tested on Debian (Etch) 4.0
Posted by Hans-Henry Jakobsen