Posts Tagged ‘ Scripts ’

Deleting folders with false ownership.

One day I have faced a situation regarding space in backup drive. On verification I found that there are many backups with false ownership and those backups with false ownerships are of users who are deleted from the system in past. So I decided to write a one liner by which can delete/remove all those backups.

One liner:

1. The following one liner will list all those backups in /backup/serverbackup/home/ with false ownership.

1
2
3
4
for i in $(find /backup/serverbackup/home/* -maxdepth 0 -nouser); \
do \
grep ^$(basename $i): /etc/passwd &>/dev/null || echo $i; \
done

2. The following one liner will list all those backups in /backup/serverbackup/home/ with false ownership and disk space used information of the same.

1
2
3
4
for i in $(find /backup/serverbackup/home/* -maxdepth 0 -nouser); \
do \
grep ^$(basename $i): /etc/passwd &>/dev/null || du -sh $i; \
done

3. The following one liner will delete all those backups in /backup/serverbackup/home/ with false ownership.

1
2
3
4
for i in $(find /backup/serverbackup/home/* -maxdepth 0 -nouser); \
do \
grep ^$(basename $i): /etc/passwd &>/dev/null || rm -rvf $i ; \
done
Advertisements

Script For DNS forwarding of all accounts under a RESELLER Account

updateResellerDNS.sh

Written By Nazeem S
Copy the bellow content and put it in file called “updateResellerDNS.sh” and give permission 755(executable) then run it (sh updateResellerDNS.sh or ./updateResellerDNS.sh)

############# Starting ########################
###############NAZEEM S####################
#############################################
#! /bin/bash
>/var/log/updateResellerDNS.log
>user
>domains
echo -n “Enter Reseller Account Name:— ”
read a
echo -n “Enter IP to be Changed (Source IP):— ”
read b
echo -n “Enter the New IP (Destination IP):— ”
read c
grep $a /etc/trueuserowners |cut -d ‘:’ -f1|sort >user

for i in `cat user`
do
cat /etc/userdomains|grep $i |cut -d: -f1|sort >>domains;
done
for x in `cat domains`
do
ls /var/named/ |grep $x|sort >>updateResellerDNS.log;
done
for y in `cat updateResellerDNS.log`
do
#replace ‘$b’ ‘$c’ –/var/named/$y;
sed -i ‘s/$b/$c/g’ /var/named/$y;
echo “$y—————- converted”
done
export c=`cat updateResellerDNS.log | wc -l`
echo “Total count of zone files has been updated = $c”
echo “log file on /var/log/updateResellerDNS.log”
#############################################
###############NAZEEM S####################
############### Ending #######################