Script to update folder/file permissions
Lets start with a basic one
Imagine that you want to update all the file permissions under a particular folder. Going down each at a time would be a hectic job, here a single line shell script can make the job easier
say you want to update all file permission to 644 under folder /home/job1/public_html/ then the script is as follows
find /home/job1/public_html/* -type f -exec chmod 644 {} \;
Similarly to update all directories permission to 755 run
find /home/job1/public_html/* -type d -exec chmod 755 {} \;
Restore domains on cPanel server
cat /etc/userdomains | awk '{print $2}' > /testing
for x in $(cat /root/users.txt); do /scripts/restorepkg --force /backup/cpbackup/daily/$x.tar.gz; done;
Display Accounts under a cPanel reseller
grep -Rl OWNER=reseller_acct_name /var/cpanel/users|wc -l
Display account using emailips that belong to reseller
for i in `cat /etc/mailips |grep -v '\*' |awk -F: '{print $1}'`;do /scripts/whoowns $i |grep freshroa;done |wc -l
Script to update Nameserver In a DNS file
This one is was developed to update the Nameserver on a file
#!/bin/bash
#
# change_nameservers.sh
#
#
# This script changes all instances of currentNS1 to newNS1 and currentNS2 to newNS2
# in /var/named/.
#
# IMPORTANT : MAKE SURE YOU HAVE A BACKUP OF /var/named/ and move it back
# if anything goes wrong! ( just to be on the safer side Razz )
#
#
currentNS1="ns3\.nhsdns\.com"
currentNS2="ns4\.nhsdns\.com"
newNS1="ns1\.nhsdns\.com"
newNS2="ns2\.nhsdns\.com"
for i in `find /var/named/ -type f -name "*.db"`
do
# number=`cat $i | sed -ne '/[0-9]\{10\}/p'| cut -f1 -d";"` # current serial number on the zone file
# new_count=`expr $number + 1`
# sed -e "s/[0-9]\{10\}/$new_count/g" $i >> ${i}.t
# sed -e "s/$currentNS1/$newNS1/g" ${i}.t >> ${i}.tmp
sed -e "s/$currentNS1/$newNS1/g" ${i} >> ${i}.tmp
sed -e "s/$currentNS2/$newNS2/g" ${i}.tmp >> ${i}.cpy
# rm -rf ${i} ${i}.t ${i}.tmp
rm -rf ${i} ${i}.tmp
mv ${i}.cpy ${i}
Script to print the NS of each domain
Script to print the NS of each domain on server(Here it was a cPanel server)
#!/bin/bash
cat /etc/trueuserdomains | awk -F: '{print $1}' > /domains
for i in `cat /domains` ; do
echo "DNS DETAILS FOR DOMAIN $i " >> /finalresult
echo "###########################################" >> /finalresult
grep NS /var/named/$i.db | awk '{print $5}' | sed 's/.$//g' >> /finalresult
echo "" >> /finalresult
done
OR#!/bin/bash
cat /etc/trueuserdomains | awk '{print $1}' | cut -d':' -f1 > /test
for i in `cat /test`; do
echo DNS DETAILS FOR DOMAIN $i | sed -e a"###########################################" >> fite
sed -n 's/NS/&/p' /var/named/$i.db | awk '{print $5}' | cut -d'.' -f1,2,3 >> /fite
echo >> /fite
done
Note:
$-------last
^========first
Script to chk load in all containers of a vps
for x in $(vzlist -a | awk '{print $1}') ; do vzlist -a | grep $x && vzctl exec $x w ;echo -e \n;done
Script to backup account on server
The below script should help to force backups for particular domains on server . Line "ls /var/cpanel/users | grep '^a' > a.txt " copies account names starting with alphabet a to a file a.txt, which is then called and processed .
If you want to run account name starting with say a, b, c, d, e, f then the line "ls /var/cpanel/users | grep '^a' > a.txt " can be replaced as "ls /var/cpanel/users | grep -E '^a|^b|^c|^d|^e|^f'"
#!/bin/bash
ls /var/cpanel/users | grep '^a' > a.txt
cat ./a.txt | while read CPUSER; do
echo "Now processing ${CPUSER} ..."
/scripts/pkgacct ${CPUSER}
done
Script to update the cron job file whenever a file is created on a particular path
#!/bin/bash
FILELIST=/home/reshma/Reshma/ftp/oldnames.txt
NEWLIST=/home/reshma/Reshma/ftp/filenames.txt
find . -type f | cut -d/ -f2 >>filenames.txt
comm -3 oldnames.txt filenames.txt > difference.txt
if [[ -s $difference.txt ]]
then
exit
else
sed 's/^/php -q /' difference.txt > change.php
sed 's/^/php -q /' difference.txt >> run_cmds.txt
#echo ".php" |
sed -i 's/$/ run/' run_cmds.txt
fi
rm -f oldnames.txt
rm -f difference.txt
mv filenames.txt oldnames.txt
www) to pre-scan backups
Help to monitor loadstatus and exim from a single window
watch 'date;hostname;exim -bpc;echo " Current Load Status" ;cat /proc/loadavg'
Lets start with a basic one
Imagine that you want to update all the file permissions under a particular folder. Going down each at a time would be a hectic job, here a single line shell script can make the job easier
say you want to update all file permission to 644 under folder /home/job1/public_html/ then the script is as follows
find /home/job1/public_html/* -type f -exec chmod 644 {} \;
Similarly to update all directories permission to 755 run
find /home/job1/public_html/* -type d -exec chmod 755 {} \;
Restore domains on cPanel server
cat /etc/userdomains | awk '{print $2}' > /testing
for x in $(cat /root/users.txt); do /scripts/restorepkg --force /backup/cpbackup/daily/$x.tar.gz; done;
Display Accounts under a cPanel reseller
grep -Rl OWNER=reseller_acct_name /var/cpanel/users|wc -l
Display account using emailips that belong to reseller
for i in `cat /etc/mailips |grep -v '\*' |awk -F: '{print $1}'`;do /scripts/whoowns $i |grep freshroa;done |wc -l
Scrpt to list files not owned by a specific user
find /home/reshma \! -user reshma -exec echo "{}" \;Script to update Nameserver In a DNS file
This one is was developed to update the Nameserver on a file
#!/bin/bash
#
# change_nameservers.sh
#
#
# This script changes all instances of currentNS1 to newNS1 and currentNS2 to newNS2
# in /var/named/.
#
# IMPORTANT : MAKE SURE YOU HAVE A BACKUP OF /var/named/ and move it back
# if anything goes wrong! ( just to be on the safer side Razz )
#
#
currentNS1="ns3\.nhsdns\.com"
currentNS2="ns4\.nhsdns\.com"
newNS1="ns1\.nhsdns\.com"
newNS2="ns2\.nhsdns\.com"
for i in `find /var/named/ -type f -name "*.db"`
do
# number=`cat $i | sed -ne '/[0-9]\{10\}/p'| cut -f1 -d";"` # current serial number on the zone file
# new_count=`expr $number + 1`
# sed -e "s/[0-9]\{10\}/$new_count/g" $i >> ${i}.t
# sed -e "s/$currentNS1/$newNS1/g" ${i}.t >> ${i}.tmp
sed -e "s/$currentNS1/$newNS1/g" ${i} >> ${i}.tmp
sed -e "s/$currentNS2/$newNS2/g" ${i}.tmp >> ${i}.cpy
# rm -rf ${i} ${i}.t ${i}.tmp
rm -rf ${i} ${i}.tmp
mv ${i}.cpy ${i}
Script to print the NS of each domain
Script to print the NS of each domain on server(Here it was a cPanel server)
#!/bin/bash
cat /etc/trueuserdomains | awk -F: '{print $1}' > /domains
for i in `cat /domains` ; do
echo "DNS DETAILS FOR DOMAIN $i " >> /finalresult
echo "###########################################" >> /finalresult
grep NS /var/named/$i.db | awk '{print $5}' | sed 's/.$//g' >> /finalresult
echo "" >> /finalresult
done
OR#!/bin/bash
cat /etc/trueuserdomains | awk '{print $1}' | cut -d':' -f1 > /test
for i in `cat /test`; do
echo DNS DETAILS FOR DOMAIN $i | sed -e a"###########################################" >> fite
sed -n 's/NS/&/p' /var/named/$i.db | awk '{print $5}' | cut -d'.' -f1,2,3 >> /fite
echo >> /fite
done
Note:
$-------last
^========first
Script to chk load in all containers of a vps
for x in $(vzlist -a | awk '{print $1}') ; do vzlist -a | grep $x && vzctl exec $x w ;echo -e \n;done
Script to backup account on server
The below script should help to force backups for particular domains on server . Line "ls /var/cpanel/users | grep '^a' > a.txt " copies account names starting with alphabet a to a file a.txt, which is then called and processed .
If you want to run account name starting with say a, b, c, d, e, f then the line "ls /var/cpanel/users | grep '^a' > a.txt " can be replaced as "ls /var/cpanel/users | grep -E '^a|^b|^c|^d|^e|^f'"
#!/bin/bash
ls /var/cpanel/users | grep '^a' > a.txt
cat ./a.txt | while read CPUSER; do
echo "Now processing ${CPUSER} ..."
/scripts/pkgacct ${CPUSER}
done
Script to update the cron job file whenever a file is created on a particular path
#!/bin/bash
FILELIST=/home/reshma/Reshma/ftp/oldnames.txt
NEWLIST=/home/reshma/Reshma/ftp/filenames.txt
find . -type f | cut -d/ -f2 >>filenames.txt
comm -3 oldnames.txt filenames.txt > difference.txt
if [[ -s $difference.txt ]]
then
exit
else
sed 's/^/php -q /' difference.txt > change.php
sed 's/^/php -q /' difference.txt >> run_cmds.txt
#echo ".php" |
sed -i 's/$/ run/' run_cmds.txt
fi
rm -f oldnames.txt
rm -f difference.txt
mv filenames.txt oldnames.txt
Scanning backups for symlinks before restoring in cPanel
tar -ztvf file.tar.gz | grep ' -> ' |egrep -v "(homedir/public_html|homedir/Help to monitor loadstatus and exim from a single window
watch 'date;hostname;exim -bpc;echo " Current Load Status" ;cat /proc/loadavg'
No comments:
Post a Comment