Squid acl Multiple Ips Script

 

Hello,

The following shell script will help you to add multiple IPs to squid configuration, you need to add all the IP address which you like to configure in squid in a file called “iplist” and then execute the following script. Make sure you take a backup of your squid.conf file before executing this script.

#!/bin/bash

awk '{printf "acl ip""%s \t%s\n",NR, "myip" " " $0}' iplist >> /etc/squid/squid.conf

awk '{printf "tcp_outgoing_address" " " $0 " " "ip%s \t%s\n",NR,$5}' iplist >> /etc/squid/squid.conf

/etc/init.d/squid restart

so that the acl will look something like the following.

acl ip1       myip xx.xx.xx.x1
tcp_outgoing_address xx.xx.xx.x1 ip1 
acl ip1       myip xx.xx.xx.x2
tcp_outgoing_address xx.xx.xx.x2 ip2





That’s it. You are done. 🙂

Linux Server Backup Amazon s3

Hello,

Now you can download amazon backups directly to your server rather than being downloaded to local machine and uploading to the server. You can follow the steps below to achieve that.

wget http://s3tools.org/repo/CentOS_5/s3tools.repo

you need to download this repo and store it in

/etc/repo.d

then use yum command to download the s3cmd

yum install s3cmd 

then you will have the command called “s3cmd”

using that u can upload/download s3 backups directly via command line.

s3cmd --configure

using the above command you need to provide the access key secret keys

 s3cmd ls s3://yourbucketname 

the above command will list the backup files at tptfirst in amazon

and to download you can use

s3cmd get s3://yourbucketname/yourbackupdata.20120724.sql.bz2

to upload you can use the following command

s3cmd put yourbackupdata2012207.sql.bz2 s3://yourbucketname/yourbackupdata201207.sql.bz2 

Reference : http://jackal777.wordpress.com/2011/03/22/cpanel-backup-to-amazon-s3/

Linux Logical Volume Extend Size

 

Hi,

 

You can extend a volume size in linux by just following the commands below

If you want to extend a size of volume /dev/mapper/volume-var to 400GB you need enter the following command.

lvextend -L400GB /dev/mapper/volume-var

O/P

Extending logical volume var to 400.00 GiB
  Logical volume usr successfully resized

Then resize the volume

resize2fs /dev/mapper/volume-var

O/P

resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/volume-var is mounted on /var; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 7
Performing an on-line resize of /dev/mapper/volume-var to 26214400 (4k) blocks.
The filesystem on /dev/mapper/volume-var is now 26214400 blocks long.

 

You are done with lvm extending.
[Note: For /var and / partitions you will not be able to unmount them but you may resize the partition without unmounting and it is at your own risk of data loss].

Thank you for viewing https://helpinlinux.com

deleted /dev partition linux

Hello,

If you have accidentally deleted /dev partition then you will face issues in ssh for sure, so you may try the following fixes via console so that ssh may start.

Try restarting sshd

/etc/init.d/sshd restart 

if you receive the following output

/dev/null no such file or directory

then

cd /dev
ls -al null
O/P

ls: cannot access null: No such file or directory
then you need to create one.

mknod /dev/null c 1 3
chmod 666 /dev/null
/etc/init.d/sshd restart

O/P

PRNG is not seeded

means your urandom file not present now, you need to create it

ls -al /dev/urandom
ls: cannot access /dev/urandom: No such file or directory
mknod /dev/urandom c 1 9

now restart sshd.

/etc/init.d/sshd restart

O/p

Stopping sshd:               [  OK  ]
Starting sshd:               [  OK  ]

Cool, your sshd is now restarted, however when you login via ssh you may receive the following error and cannot access the server’s commandline.

login as: root
root@xx.xx.xx.xx's password:
Server refused to allocate pty

So, now you need to create pty and tty by the following command.

/sbin/MAKEDEV pty
/sbin/MAKEDEV tty

now you will be able to access server via ssh. 🙂

Reference:

Sample perl script to print hello world

 

Hi,

 

This post is a simple perl script to print the sentence “Hello World”.

 

#/usr/bin/perl -w

print "Hello World \n";

 

Output:

 Hello World

 

Here I have added \n to make the perl compiler to end the particular line. Make sure that you use “”(double quotes) rather than ”(single quotes) because by default perl won’t compile the values inside single quotes. So the output will print \n also. Something like “Hello World \n” which is not a desired output which we require.

 

Thanks for viewing helpinlinux.com

CPU utilization in linux script alert

Hi,

This below script will update you whenever the server load goes beyond 15 with the load and the top 10 process which uses maximum CPU.

#!/bin/bash
SUBJECT="`hostname`server load is high"
TO=user@host.com
uptime > /tmp/load
if [ `uptime | awk '{ print$10 }' | cut -d. -f1` -gt 15 ];
then
echo "============================================" >> /tmp/load
`ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10 >> /tmp/load `
mail -s "$SUBJECT" $TO < /tmp/load
exit
fi

Thanks for viewing helpinlinux.com

ioncube php loader ioncube_loader_lin_5.2.so

Hi,

ioncube php loader ioncube_loader_lin_5.2.so to be installed by the site administrator

If you are getting the above error after installing softaculous in your cPanel. Then probably you should run the following command to fix the issue.

#/scripts/makecpphp

Thanks for viewing helpinlinux.com

Increase Swap Size in Linux

Hi,

Would you like to increase swap size in Linux. You may follow the below steps to do that.
 
Here I am increasing the swap size from 2GB to 4GB.
 
The free -m command shows that the swap memory is now 2GB,

root@server[~]# free -m
total used free shared buffers cached
Mem: 3954 3824 130 0 175 2091
-/+ buffers/cache: 1558 2396
Swap: 2047 0 2047

Now,
 
To create a swap file of 4GB you need to execute the following command.

root@server[~]#dd if=/dev/zero of=/path/to/new/swap bs=1M count=4096

This will create a new partition with 4GB space. To make it a swap partition you need to execute the following command.

root@server[~]# mkswap /path/to/new/swap

Now the swap file is created.

Next you need to properly edit fstab entry to replace the previous swap line. Previously it would be something like below entry.

LABEL=SWAP-sda6         swap                    swap    pri=0,defaults        0 0

You need to change it to the following

/path/to/new/swap         swap                    swap    pri=0,defaults        0 0

and now save the fstab file and exit.

now turn the swap to off and then on it using the below command.

root@server[~]# swapoff
root@server[~]# swapon

This will mount the new swap file. So you will the output as below.

root@server[~]# free -m
total used free shared buffers cached
Mem: 3954 3773 181 0 111 2048
-/+ buffers/cache: 1613 2341
Swap: 4096 0 4096 

Please reboot the server if you need to check if the changes in fstab is working onboot.

Thank you for viewing helpinlinux.com

Backup cPanel Account SSH

Hi,

 

Is your server loaded heavily while cPanel backup is running? You can use the following script to backup Entire cPanel account’s home directory, please note that you need to backup MySQL database separately, for MySQL database backup you may use the link here.

 

#!/bin/bash
#! Script to Backup cPanel Accounts

for x in `awk '{print $2}' /etc/userdomains | sed -e '/nobody/d'`

do
ssh root@xx.xx.xx.xx mkdir -p /backup/$x

rsync -arv /home/$x/* root@xx.xx.xx.xx:/backup/$x/.
done

 

Thank you for viewing helpinlinux.com

Plesk Website Mail and Database Backup Script

Hello,

Is your server loaded heavily while Plesk backup is running? You can use following script will help you backing up mail, and website contents of your plesk server, you need to execute this is your plesk server. All you need to have is password less authentication from your plesk server to backup server. Replace xx.xx.xx.xx with your backup sever IP. For database backup you may use the link.

 

#!/bin/bash
#!Script to Backup Mail and website contents of Plesk accounts
cd /var/www/vhosts

for x in `ls -d * |tr -d /`

do

ssh xx.xx.xx.xx mkdir -p /web/backup/path/$x
rsync -arzv -e /var/www/vhosts/$x/httpdocs/* root@xx.xx.xx.xx:/web/backup/path/$x/httpdocs/.

ssh xx.xx.xx.xx mkdir -p /mail/backup/path/$x
rsync -arv -e  /var/qmail/mailnames/$x/* root@xx.xx.xx.xx:/mail/backup/path/$x/.

done

cd /var/lib/mysql
for DBs in $(ls -d */ |tr -d /)
do

cd /mysqlbackup

`mysqldump -u admin -p'password' $DBs > $DBs.sql`

done

`ssh root@xx.xx.xx.xx mkdir -p /mysql/backup/path/`
rsync -avr /mysqlbackup/* ssh root@xx.xx.xx.xx:/mysql/backup/path/.

 

Thank you for viewing helpinlinux.com