All Entries Tagged With: "script"
Script for restoring multiple accounts from backup
The following script can be used to restore multiple accounts from the backups.
It is assumed that all the backup files are already present in the /home directory in the tar.gz format.
#!/bin/bash
#######################
for i in `ls | grep tar.gz | cut -d- -f2 | cut -d. -f1`
do
echo “Restoring $i….”
/scripts/restorepkg $i
echo “$i restored”
echo “====================”
done
echo “Restoration completed”
#######################
Shell script for packaging all accounts
Issue :
How can I run a ‘pkgacct’ for all the accounts on the server in one go?
Solution:
Here’s a simple script to package all the accounts on your server :
#!/bin/bash
IFS=”$”
/bin/ls — /var/cpanel/users | /bin/grep -v “\.\|root\|mysql\|nobody\|cpanel” | while read CPUSER; do
/scripts/pkgacct “${CPUSER}”
done
Useful cPanel scripts and their functions
Following are the cPanel scripts and their functions.
adddns – Adds a DNS zone.
addfpmail – Add frontpage mail extensions to all domains without them.
addfpmail2 -Add frontpage mail extensions to all domains without them.
addnetmaskips – Add the netmask 255.255.255.0 to all IPs that have no netmask.
addnobodygrp – Adds the group nobody and activates security.
addpop – Add a [...]
Script to auto-delete emails older than a year
Issue :
Emails older than a year need to be deleted automatically.
Solution :
You can use ‘find’ against the standard mail folders :
find -P /home/*/mail/*/*/cur -mtime ‘+365′
find -P /home/*/mail/*/*/new -mtime ‘+365′
Note : 365 is the number of days in a year. You can change this number as per your requirement.
This will give you a [...]
Script for clearing unwanted queued emails from the server
Here is a small but handy script which will clear the queued emails from the server.
exim -bpc
exim -bpru | grep frozen | awk {’print $3′}|xargs exim -Mrm
exim -bpru | grep “<>” | awk {’print $3′}|xargs exim -Mrm
exim -bpru | grep “nobody” | awk {’print $3′}|xargs exim -Mrm
exim -bpru|awk {’print $3′}|xargs exim -Mrm
exiqgrep -o 86400 -i [...]
Log cleaner script
This script will clear the apache logs, cpanel logs and the logs in /var. It will take a zipped backup before clearing logs.
#!/bin/bash
# Script to Clear Logs
echo “Clearing Logs in /var…..”
cd /var/log
for i in `ls -lSh /var/log|grep -v gz|grep “\-rw”|head -15|awk {’print $9′}`
do
cp -p “$i” “$i”.bak
echo “”>$i
if [ -e "$i".bak.gz ]
then
mv “$i”.bak.gz “$i”.bak1.gz
fi
gzip “$i”.bak
done
echo “Clearing [...]
Script to list all the open ports
This could be a very good utility to check the open ports in the server.
#!/bin/sh
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
if [ -e /etc/master.passwd ]; then
netstat -an | grep LISTEN | grep “*” | awk ‘{print $4 }’ | cut -d. -f2 | sort -n | uniq
else
netstat -an | grep LISTEN | grep -v STREAM | grep : | awk [...]
Script for Reseller check and Adding Vhost
Description:
The following script will determine the shared user type I.E normal shared user, reseller or resold. In addition the script will also display the number of number of ModRails or Mongrel instances and the port used. While entering a reseller or resold account name the details of Mongrel / ModRails instances of all the users [...]

