IndianWebPortal.com

Something Different In Linux

Home » Archive by category 'Shell Programming and Scripting'

We can set the cron to restart the server when it was down or not running. You can use following script to detect and restart the httpd,ngnix,Serv-U or any other services. 1) Create the file vi /root/autorestart.sh and add the following code and save it. You can replace the Serv-U with any your service like  [ Read More ]

How to check NFS mount point by using the script ? Ans : If you we have mounted the NFS directory one or  more servers and you want to monitor that mount point then you can use the following method. 1) Check the mount point directoy name, in the following example the mount directory name  [ Read More ]

Q. How to run bash script from local machine to remote linux machine ? Ans : We can run the bash script from our local machine to remote machine without login to remote server. We will get the result of some commands on our local machine. The syntax of this command is ssh [user]@[server] ‘[command]’  [ Read More ]

The following script is used to  start mysql automatically when it is failed or stopped on the server. You can set 2 min cron “*/2 * * * * /bin/sh /root/automysqlstart.sh” and it restart the mysql automatically. ============================ #!/bin/bash #Checking whether MySQL is alive or not if mysqladmin ping | grep -q “alive”; then echo “MySQL is  [ Read More ]

You can use the following script to auto restart the nginx on the server. The following script check the status and if it is down then it restart. You can set cron  “* * * * * /bin/sh /root/autongnixrestart.sh” ========================== #! /bin/sh set -e PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC=”nginx daemon” NAME=nginx DAEMON= /usr/sbin/$NAME SCRIPTNAME=/etc/init.d/$NAME test -x $DAEMON || exit  [ Read More ]

Question : How to terminate old suspended accounts on cpanel server ? Ans:  You can terminate the 90 days old suspended accounts by using the following script. 1) vi /root/terminatesuspended.sh ================== for i in `find /var/cpanel/suspended/ -mtime +90 | cut -d’/’ -f5 | sed ‘1 d’` do y | /scripts/killacct $i –killdns n; done; ==================  [ Read More ]

How to find out the reseller name with domains? Ans : If you want to list all cPanel accounts under a specific reseller, then you can use the below simple shell script. 1) Crete the file reseller.sh and add the following code. vi /home/reseller.sh ========================================================== #!/bin/bash usage() { echo “Example : $0 domain.com or username”  [ Read More ]

Following are the steps to take increment backup of reseller account on backup server. 1) First we need to find out the user name which is under the reseller account. On shared/source server :- vi /home/resellerUsername/backup.sh # For finding the username under the reseller account cat /etc/trueuserowners | grep resellerUsername | awk -F: ‘{print $1}’  [ Read More ]

It’s always a good practice & from the security point of view to get notified instantly through an email when someone logs into your server through SSH with root privileges. Open the file .bashrc for the root user. Vi /root/.bashrc enter the following code into echo ‘SSH Root Access (Your Server Name) on:’ `date` `who`  [ Read More ]

Make your shell colorful

Posted by Rishikesh Vispute Categories: Basic Linux, FUN, Shell Programming and Scripting

You can easily changed your black ssh screen to colorful screen by using following steps. 1) Login to the server via SSH as root 2) Edit the .bash_profile file found in the /root directory & paste the following line: vi  .bash_profile export PS1=”\[$(tput bold)$(tput setb 4)$(tput setaf 7)\]\u@\h:\w $ \[$(tput sgr0)\]” Save & quit the  [ Read More ]

Some common script

Posted by Rishikesh Vispute Categories: Shell Programming and Scripting

1 ) Script to change server wide ownership for all cpanel users. ==================== #!/bin/bash cd /var/cpanel/users for user in * do chown -Rv $user.$mail /home/$user/etc chown -v $user.$nobody /home/$user/public_html chown -Rv $user.$user /home/$user done ====================

If you want to set the expiration to your site   means after some date or year your site shows custom error on the page then you can add following code in index page below the “<?php” code  and set the date as per your request. ============================================ $exp_date = “2010-04-31″; $todays_date = date(“Y-m-d”); $today =  [ Read More ]

How to set correct ownership to all account on the cPanel server. You can use the following commands to set the correct ownership for all accounts which is hosted on the cPanel server. =============================== for i  in `cat /etc/trueuserdomains   | awk ‘{print $2}’` > do > chown $i.$i /home/$i -R; > chown $i.mail /home/$i/etc -R;  [ Read More ]

test cgi script

Posted by Rishikesh Vispute Categories: Knowledge, Shell Programming and Scripting

Create one test.cgi file and add the folloing test code for checking the .cgi file working on the server. ======================= #!/usr/local/bin/perl # hello.pl — my first perl script! print “Content-type: text/html\n\n”; print “Hello, world!\n”; =======================

some IMP script

Posted by Rishikesh Vispute Categories: Shell Programming and Scripting

1) Script for finding username from /etc/trueuserowners file and save it user.txt file cat /etc/trueuserowners | awk ‘{print $2}’ > user.txt or cat /etc/trueuserdomains | awk ‘{print $1}’ > user.txt 2) Script for remove .htaccess or any file from current(.) directory find . -name .htaccess | xargs rm -rf

If you want to migrate more accounts from one server to another server then you need to create packages for each accounts . You can easilly create packages by using this script. 1) Create one Migarting-Accounts.txt file and add the the user name , which you want to create packages. 2) Create Migration directory for  [ Read More ]

Popular Posts

remove index.php fro

How to remove index.php from url in magento Ans : If you ...

PHP-Java bridge on p

  What is php-java bridge? The php-java bridge is the php ...

Set expiration for y

If you want to set the expiration to your site ...

Warning: Parameter 1

Error: Warning: Parameter 1 to modMainMenuHelper::buildXML() expected to be a ...

domain pointing to e

If you domain uses external MX record and it is ...