Linux commands


Linux in a Nutshell (cover)

Alphabetical Directory of Linux Commands

Click on any of the 687 commands below to get a description and list of available options.


[a] [b] [c] [d] [e] [f] [g] [h] [i] [j] [k] [l] [m]
[n] [o] [p] [q] [r] [s] [t] [u] [v] [w] [x] [y] [z]

a

accept
access
aclocal
aconnect
acpi
acpi_available
acpid
addr2line
addresses
agetty
alsactl
amidi
amixer
anacron
aplay
aplaymidi
apm
apmd
apropos
apt
ar
arch
arecord
arecordmidi
arp
as
at
atd
atq
atrm
audiosend
aumix
autoconf
autoheader
automake
autoreconf
autoscan
autoupdate

b

badblocks
banner
basename
bash
batch
bc
biff
bison
bzcmp
bzdiff
bzgrep
bzip2
bzless
bzmore

c

c++
c++filt
cal
cardctl
cardmgr
cat
cc
cdda2wav
cdparanoia
cdrdao
cdrecord
cfdisk
chage
chattr
chfn
chgrp
chkconfig
chmod
chown
chpasswd
chroot
chrt
chsh
chvt
cksum
clear
cmp
col
colcrt
colrm
column
comm
compress
cp
cpio
cpp
crond
crontab
csplit
ctags
cupsd
cut
cvs

d

date
dd
deallocvt
debugfs
depmod
devdump
df
diff
diff3
dig
dir
dircolors
dirname
disable
dlpsh
dmesg
dnsdomainname
dnssec-keygen
dnssec-makekeyset
dnssec-signkey


dnssec-signzone
doexec
domainname
dosfsck
du
dump
dumpe2fs
dumpkeys

e

e2fsck
e2image
e2label
echo
edquota
egrep
eject
elvtune
emacs
enable
env
envsubst
esd
esd-config
esdcat
esdctl
esddsp
esdmon
esdplay
esdrec
esdsample
etags
ex
expand
expr

f

factor
false
fc-cache
fc-list
fdformat
fdisk
fetchmail
fgconsole
fgrep
file
find
finger
fingerd
flex
fmt
fold
formail
free
fsck
ftp
ftpd
fuser

g

g++
gawk
gcc
gdb
getent
getkeycodes
gpasswd
gpg
gpgsplit
gpgv
gpm
gprof
grep
groff
groffer
groupadd
groupdel
groupmod
groups
grpck
grpconv
gs
gunzip
gzexe
gzip

h

halt
hdparm
head
hexdump
host
hostid
hostname
htdigest
hwclock

i

iconv
id
ifconfig
imapd
inetd
info
init
insmod
install
ipcrm
ipcs
iptables
iptables-restore
iptables-save
isodump
isoinfo
isosize
isovfy
ispell

j

join

k

kbd_mode
kbdrate
kernelversion
kill
killall
killall5
klogd
kudzu

l

last
lastb
lastlog
ld
ldconfig
ldd
less
lesskey
lftp
lftpget
link
ln
loadkeys
locale
locate
lockfile
logger
login
logname
logrotate
look
losetup
lpadmin
lpinfo
lpmove
lpq
lpr
lprm
lpstat
ls
lsattr
lspci
lsmod
lsusb

m

m4
mail
mailq
mailstats
mailto
make
makedbm
makemap
man
manpath
mattrib
mbadblocks
mcat
mcd
mcopy
md5sum
mdel, mdeltree
mdir
mdu
merge
mesg
metamail
metasend
mformat
mimencode
minfo
mkdir
mkdosfs
mke2fs
mkfifo
mkfs
mkfs.ext3
mkisofs
mklost+found
mkmanifest
mknod
mkraid
mkswap
mktemp
mlabel
mmd
mmount
mmove
modinfo
modprobe
more
mount
mountd
mpartition
mpg123
mpg321
mrd
mren
mshowfat
mt
mtools
mtoolstest
mtype
mv
mzip

n

named
namei
nameif
netstat
newaliases
newgrp
newusers
nfsd
nfsstat
nice
nm
nohup
nslookup
nsupdate

o

objcopy
objdump
od
openvt

p

passwd
paste
patch
pathchk
perl
pidof
ping
pinky
pmap
portmap
poweroff
pppd
pr
praliases
printenv
printf
ps
ptx
pwck
pwconv
pwd
python

q

quota
quotacheck
quotaon
quotaoff
quotastats

r

raidstart
ramsize
ranlib
rarpd
rcp
rdate
rdev
rdist
rdistd
readcd
readelf
readlink
reboot
reject
rename
renice
repquota
reset
resize2fs
restore
rev
rexec
rexecd
richtext
rlogin
rlogind
rm
rmail
rmdir
rmmod
rndc
rootflags
route
routed
rpcgen
rpcinfo
rpm
rsh
rshd
rsync
runlevel
rup
ruptime
rusers
rusersd
rwall
rwho
rwhod

s

sane-find-scanner
scanadf
scanimage
scp
screen
script
sdiff
sed
sendmail
sensors
seq
setfdprm
setkeycodes
setleds
setmetamode
setquota
setsid
setterm
sftp
sh
sha1sum
showkey
showmount
shred
shutdown
size
skill
slabtop
slattach
sleep
slocate
snice
sort
split
ssh
ssh-add
ssh-agent
ssh-keygen
ssh-keyscan
sshd
stat
statd
strace
strfile


strings
strip
stty
su
sudo
sum
swapoff
swapon
sync
sysctl
sysklogd
syslogd

t

tac
tail
tailf
talk
talkd
tar
taskset
tcpd
tcpdump
tcpslice
tee
telinit
telnet
telnetd
test
tftp
tftpd
time
tload
tmpwatch
top
touch
tr
tracepath
traceroute
troff
true
tset
tsort
tty
tune2fs
tunelp

u

ul
umount
uname
uncompress
unexpand
unicode_start
unicode_stop
uniq
uptime
useradd
userdel
usermod
users
usleep
uudecode
uuencode
uuidgen

v

vdir
vi
vidmode
vim
vmstat
volname

w

w
wall
warnquota
watch
wc
wget
whatis
whereis
which
who
whoami
whois
write

x

xargs
xinetd

y

yacc
yes
ypbind
ypcat
ypinit
ypmatch
yppasswd
yppasswdd
yppoll
yppush
ypserv
ypset
yptest
ypwhich
ypxfr

z

zcat
zcmp
zdiff
zdump
zforce
zgrep
zic
zless
zmore
znew


--

script to search only or search and replace exact pattern

Bellow is a script to search only or  search and replace exact pattern .If you have any sugggestion to this script that would help in ease  system administration task ... be free to suggest.
 
#!/bin/bash
clear

search_pattern ()
{
read -p " Enter the path where your text file is loscated: " p
read -p "Enter the pattern you want to serch: " pat
pattern=`sed -n "\|$pat|p" $p`

if [ -n "$pattern"  ]; then
echo -e "$pattern"
else
echo -e "######### The pattern cannot be found #########"
fi
}

replace_pattern ()
{
read -p " Enter the path where your text file is loscated: " p
read -p "Enter the pattern you want to serch: " pat
read -p "Enter the pattern you want to replace: " reppat
pattern=`sed -n "\|$pat|p" $p`
if [ -f "$p" ]; then

   if [ -n "$pattern"  ]; then

sed -i  "s|$pat|$reppat|" $p
  else
echo -e "######### the pattern is not found ############# "
   fi
else
echo -e "############ the file is not found #############"
fi
}

read -p " What do you ant to do: [ search or replace ]: " t

case $t in
search ) search_pattern
;;
replace ) replace_pattern
;;
* ) echo -e "please enter search or replace"

esac
 

--

backup manager shell script

the scripts assumes the following :
1) websites are located at websites/daomin.com
2) this script can delete add edit dail - monthly -weekly backups
3) there is cron script in /etc/cron.daily/website_backup wit he following vaiables subsitution ar the geginning od the script !!
dailly=`date +%H`
weekly=`date +%a`
monthly=`date +%d`
mark=`date +%C%a%B%Y`
 
 
 
#!/bin/bash
clear


daily_backup ()
{
test_website=`sed -n  /"\<${d}2631\>"/,/"\<${d}2631\>"/p /etc/cron.daily/website_backup`
website_backup='/etc/cron.daily/website_backup'

if [ -d /websites/$d ]; then

   if [ -d /websites/$d/$f ]; then

          if [ -d /websites/$d/backup ]; then

   if [ -z "$test_website" ]; then

cat >> $website_backup << _eof_
##################${d}2631#######################


if [ -d /websites/$d ]; then

   if [ -d /websites/$d/$f ]; then

          if [ -d /websites/$d/backup ]; then


tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d

           else
echo -e '########## the back up dir does not exist #############'
  fi
    else
echo -e '########## the folder does not exist #############'
   fi
else
echo -e '######### the domain does not exsit #########'

fi


#####################${d}2631########################
_eof_

                  else
sed -i  /"\<${d}2631\>"/,/"\<${d}2631\>"/D /etc/cron.daily/website_backup

cat >> $website_backup << _eof_
##################${d}2631#######################


if [ -d /websites/$d ]; then

   if [ -d /websites/$d/$f ]; then

          if [ -d /websites/$d/backup ]; then


tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d

           else
echo -e '########## the back up dir does not exist #############'
  fi
    else
echo -e '########## the folder does not exist #############'
   fi
else
echo -e '######### the domain does not exsit #########'

fi


#####################${d}2631########################
_eof_

                    fi
             else
echo -e "########## the backup dir does not exist #############"
  fi
       else
echo -e "########## the folder $web does not exist #############"
   fi
else
echo -e "######### the domain $d does not exsit #########"

fi

}

weekly_backup ()
{
test_website=`sed -n  /"\<${d}2631\>"/,/"\<${d}2631\>"/p /etc/cron.daily/website_backup`
website_backup='/etc/cron.daily/website_backup'

if [ -d /websites/$d ]; then

   if [ -d /websites/$d/$f ]; then

          if [ -d /websites/$d/backup ]; then

                
                    if [ -z "$test_website" ]; then

cat >> $website_backup << _eof_
##################${d}2631#######################


if [ -d /websites/$d ]; then

   if [ -d /websites/$d/$f ]; then

          if [ -d /websites/$d/backup ]; then

               if [ $weekly = "sun" ]; then

tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d
               else
echo -e  "######### today is not sunday ##########"
               fi
           else
echo -e '########## the back up dir does not exist #############'
  fi
    else
echo -e '########## the folder does not exist #############'
   fi
else
echo -e '######### the domain does not exsit #########'

fi
#####################${d}2631########################
_eof_

                  else
sed -i  /"\<${d}2631\>"/,/"\<${d}2631\>"/D /etc/cron.daily/website_backup

cat >> $website_backup << _eof_
##################${d}2631#######################


if [ -d /websites/$d ]; then

   if [ -d /websites/$d/$f ]; then

          if [ -d /websites/$d/backup ]; then

               if [ $weekly = "sun" ]; then

tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d
               else
echo -e  "######### today is not sunday ##########"
               fi

          else
echo -e '########## the back up dir does not exist #############'
          fi
    else
echo -e '########## the folder does not exist #############'
   fi
else
echo -e '######### the domain does not exsit #########'

fi


#####################${d}2631########################
_eof_
                    fi
             else
echo -e "########## the backup dir does not exist #############"
  fi
       else
echo -e "########## the folder $web does not exist #############"
   fi
else
echo -e "######### the domain $d does not exsit #########"

fi

}

monthly_backup ()
{
test_website=`sed -n  /"\<${d}2631\>"/,/"\<${d}2631\>"/p /etc/cron.daily/website_backup`
website_backup='/etc/cron.daily/website_backup'

if [ -d /websites/$d ]; then

   if [ -d /websites/$d/$f ]; then

          if [ -d /websites/$d/backup ]; then

                   if [ -z "$test_website" ]; then

cat >> $website_backup << _eof_
##################${d}2631#######################


if [ -d /websites/$d ]; then

   if [ -d /websites/$d/$f ]; then

          if [ -d /websites/$d/backup ]; then

                if [ $monthly = "31" ]; then

tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d
                else
echo -e " Today is not the 31st of the months "
                fi
          else
echo -e '########## the back up dir does not exist #############'
  fi
    else
echo -e '########## the folder does not exist #############'
   fi
else
echo -e '######### the domain does not exsit #########'

fi
#####################${d}2631########################
_eof_

                  else
sed -i  /"\<${d}2631\>"/,/"\<${d}2631\>"/D /etc/cron.daily/website_backup

cat >> $website_backup << _eof_
##################${d}2631#######################


if [ -d /websites/$d ]; then

   if [ -d /websites/$d/$f ]; then

          if [ -d /websites/$d/backup ]; then


tar cvf /websites/$d/backup/$d.$mark.tar /websites/$d

           else
echo -e '########## the back up dir does not exist #############'
  fi
    else
echo -e '########## the folder does not exist #############'
   fi
else
echo -e '######### the domain does not exsit #########'

fi


#####################${d}2631########################
_eof_
                    fi
             else
echo -e "########## the backup dir does not exist #############"
  fi
       else
echo -e "########## the folder $web does not exist #############"
   fi
else
echo -e "######### the domain $d does not exsit #########"

fi

}

delete_backup ()
{
test_website=`sed -n  /"\<${d}2631\>"/,/"\<${d}2631\>"/p /etc/cron.daily/website_backup`
website_backup='/etc/cron.daily/website_backup'

if [ -d /websites/$d ]; then

   if [ -d /websites/$d/$f ]; then

          if [ -d /websites/$d/backup ]; then

                   if [ -n "$test_website" ]; then

sed -i  /"\<${d}2631\>"/,/"\<${d}2631\>"/D /etc/cron.daily/website_backup
                   else
echo -e "the scritp for  $d does not exist"
                   fi
          else
echo -e "########## the backup dir does not exist #############"
           fi  
    else
echo -e "########## the folder $web does not exist #############"
    fi
else
echo -e "######### the domain $d does not exsit #########"
fi
}

read -p "read enter your domain name: " d
read -p "Back up to be done [ delete / daily / weekly / monthly ]: " p
read -p " Enter folder to be backed up " f



case $p in
delete ) delete_backup
;;
daily ) daily_backup
;;
weekly ) weekly_backup
;;
monthly ) monthly_backup
;;
* ) echo -e " Please enter daily , weekly or monthly "
esac



--

Database manager script

The scripts assumes the following " 
1) the websites are located at /websites/domain.com 
2) this script edits add and deletes database
 
#!/bin/bash
clear

add_DB ()
{


read -p " Enter your domain name: " d
read -p " Enter your choice of database name : " DB
read -p " Enter your user name: " u
read -p " Enter your paasword : " p

check_DB=$( mysql -u root -pagnello -e "show databases;" |grep "\<${DB}\>")

if [ -d /websites/"$d" ]; then

          if [ -z $check_DB ]; then
mysql -u root -pagnello -e "create database ${DB};"
mysql -u root -pagnello -e "GRANT ALL ON ${DB}.* to '${u}'@'localhost' IDENTIFIED BY '${p}'"

          else
echo -e "########## The database already exist ############"
          fi
else
echo -e "########## The domain does not exist #############"
fi
}

del_DB ()
{

read -p " Enter your domain name: " d
read -p " Enter your  database to be deleted  : " DB

check_DB=$(mysql -u root -pagnello -e 'show databases;' |grep "\<${DB}\>")
check_mysql_db=$(mysql -u root -pagnello -e 'use mysql;' -e "select  Db,User from db where Db='$DB';" |grep $DB |awk '{print $1}')
check_mysql_user=$(mysql -u root -pagnello -e 'use mysql;' -e "select  Db,User from db where Db='$DB';" |grep $DB |awk '{print $2}')

if [ -d /websites/"$d" ]; then

          if [ "$check_DB" = "$DB"  ]; then

                if [ "$DB" = "$check_mysql_db" ];then


mysql -u root -pagnello -e "drop database $DB;"
mysql -u root -pagnello -e 'use mysql;' -e "DELETE FROM db WHERE Db='${check_mysql_db}' AND Host='localhost'"
mysql -u root -pagnello -e 'use mysql;' -e "DELETE FROM user WHERE User='${check_mysql_user}' AND Host='localhost'"
                else
echo -e "########## The database does not match in the mysql DB file  ############"
                fi
          else
echo -e "########## The database does not exist #############"
          fi
else
echo -e "############# The domani does not exist ##########"
fi
}

edit_DB ()
{
read -p " Enter your domain name: " d
read -p " Enter your choice of database name : " DB
read -p " Enter your user name: " u
read -p " Enter your paasword : " p

check_DB=$( mysql -u root -pagnello -e "show databases;" |grep "\<${DB}\>")
check_DB=$(mysql -u root -pagnello -e 'show databases;' |grep "\<${DB}\>")
check_mysql_db=$(mysql -u root -pagnello -e 'use mysql;' -e "select  Db,User from db where Db='$DB';" |grep $DB |awk '{print $1}')
check_mysql_user=$(mysql -u root -pagnello -e 'use mysql;' -e "select  Db,User from db where Db='$DB';" |grep $DB |awk '{print $2}')

if [ -d /websites/"$d" ]; then

        if [ "$check_DB" = "$DB"  ]; then

                if [ "$DB" = "$check_mysql_db" ];then

                        if [ "$u" = "$check_mysql_user" ]; then

mysql -u root -pagnello -e 'use mysql;' -e "UPDATE user SET Password=PASSWORD('$p') WHERE user='$check_mysql_user';"
mysql -u root -pagnello -e 'use mysql;' -e "FLUSH PRIVILEGES;"

                        else
echo -e "################ the user that you enter does not exist #################"
                        fi
                else
echo -e "########## The database does not match in the mysql DB file  ############"
                fi
         else
echo -e "########## The database does not exist #############"
          fi
else
echo -e "############# The domani does not exist ##########"
fi
}

read -p "Do you want to add / delete /edit database: " r

case $r in
add ) add_DB
;;
delete ) del_DB
;;
edit ) edit_DB
;;
* ) echo -e "Please enter add / delete /edit "
esac
 
 
 --

Add IP aliases script

this script assumes the following :
1) we need to enter the config file for the IP-aliases
2) we need to enter the ip number

#!/bin/bash
clear
read -p "Enter the IP number: [example eth0:1 eth0:2]: " ip
read -p "Enter the configuration file : " cf
path=/etc/sysconfig/network-scripts/ifcfg-$cf
check=`ifconfig |grep "\<$ip\>"`

if [ ! -f /etc/sysconfig/network-scripts/ifcfg-"$cf" ]; then

if [ -z "$check" ]; then

cat >> $path << _eof_
DEVICE=$cf
BOOTPROTO=static
BROADCAST=192.168.0.255
HWADDR=00:0C:29:9D:65:6F
IPADDR=$ip
NETMASK=255.255.255.0
NETWORK=192.168.0.0
ONBOOT=yes
_eof_

echo -e "######## Added the IP aliases ##############"
ifup $cf
else
echo -e "The Ip address already exist"
fi
else
echo -e "The ip aliases $cf exist"
fi


--

add custom error pages script

this script assumes the following
1) that you a domain set up and proper vhsot directive ( see add domin script )
2) the script give option for URL or folder redirect

#!/bin/bash
clear

url_custom_error_pages ()
{
read -p "Enter your domain name: " d
read -p "Enter the error number : " e
read -p "Enter the url you want the error page  to redirect to " u

if [ -d /websites/"$d" ]; then

         if [  -z "$(sed -n "/\#add_custom_error_page_${d}_from_${e}\#/,/\#add_custom_error_page_${d}_from_${e}\#/p" /usr/local/apache2/conf/extra/httpd_vhost.conf)"  ]; then
sed -i "/\#FEATURES_${d}2631\#/a\#################add_custom_error_page_${d}_from_${e}\#################\n ErrorDocument ${e} http\:\/\/$u \n#################add_custom_error_page_${d}_from_${e}\##################" /usr/local/apache2/conf/extra/httpd_vhost.conf

/etc/init.d/httpd graceful
        else
echo -e "The custom error page already exist "
        fi
else
echo -e "the domain $d does not exist"
fi
}

folder_custom_error_pages ()
{
read -p "Enter your domain name: " d
read -p "Enter the error number : " e
read -p "Enter the foler you want the error page  to redirect to " f

if [ -d /websites/"$d" ]; then

         if [  -z "$(sed -n "/\#add_custom_error_page_${d}_from_${e}\#/,/\#add_custom_error_page_${d}_from_${e}\#/p" /usr/local/apache2/conf/extra/httpd_vhost.conf)"  ]; then
sed -i "/\#FEATURES_${d}2631\#/a\#################add_custom_error_page_${d}_from_${e}\#################\n ErrorDocument ${e} ${f} \n#################add_custom_error_page_${d}_from_${e}\##################" /usr/local/apache2/conf/extra/httpd_vhost.conf

/etc/init.d/httpd graceful
        else
echo -e "The custom erro page alread exist"
        fi
else
echo -e "the domain $d does not exist"
fi
}

read -p " do you want your error page to redirect to url or to specific folder: [ url / folder ] " r

case $r in
url ) url_custom_error_pages
;;
folder ) folder_custom_error_pages
;;
* ) echo -e " please enter ur l or folder "
esac


--

generate awstats scripts

This script assumes the following
1) you ahve install the awstat package in the folloing /usr/local/src/*
2) this script will add the cron job to run the perl- update -wasstat script every day  located at "/etc/cron.daily/awstatsupdate
3 you have a folder called /websites/domain.com/webstats and /websites/domain.com/web/awstats 
 
#!/bin/bash


echo -e " enter the domain to generate webstats "
read d

domain_user=` echo $d |sed s/\.com/com2631/g `
tmp_name=` echo $d |sed s/\.com//g `


if [ -d /websites/"$d" -a -d /websites/"$d"/webstats   ]; then
echo -e "awstats exist for this $d exist "
else
echo -e "generating awstats for $d "
mkdir /websites/"$d"/webstats

chown "$domain_user":"$domain_user"  /websites/"$d"/webstats

cp -R /usr/local/src/awstats-6.7/* /websites/"$d"/webstats

echo -e "copying source dir to the webstats dir"
sleep 2

cp /websites/"$d"/webstats/wwwroot/cgi-bin/awstats.model.conf  /websites/"$d"/webstats/wwwroot/cgi-bin/awstats."$tmp_name".sys.qualiproj.qualispace.com.conf
sleep 2  

  if [ -d /websites/"$d"/web/awstats ];then
echo -e "/web/awstats  exist "
exist 1
  else
echo -e "creating awstats"
sleep 2
mkdir /websites/"$d"/web/awstats
    fi

chown "$domain_user":"$domain_user"  /websites/$d/web/awstats
cp -R /websites/"$d"/webstats/wwwroot/icon    /websites/"$d"/web/awstats/

config_file="/websites/$d/webstats/wwwroot/cgi-bin/awstats.$tmp_name.sys.qualiproj.qualispace.com.conf"

cat >> $config_file << _eof_
LogFile="/websites/"$d"/logs/$tmp_name.sys.qualiproj.access_log"
LogType=W
LogFormat=1
LogSeparator=" "
SiteDomain="$tmp_name.sys.qualiproj.qualispace.com"
HostAliases="www.$tmp_name.sys.qualiproj.qualispace.com agnello.sys.qualiproj.qualispace.com localhost 127.0.0.1 "
DNSLookup=1
DirData="/websites/$d/webstats"
DirCgi="/cgi-bin"
DirIcons="/web/awstats/icon"
AllowToUpdateStatsFromBrowser=0
AllowFullYearView=2
EnableLockForUpdate=0
DNSStaticCacheFile="dnscache.txt"
DNSLastUpdateCacheFile="dnscachelastupdate.txt"
SkipDNSLookupFor=""
AllowAccessFromWebToAuthenticatedUsersOnly=0
AllowAccessFromWebToFollowingAuthenticatedUsers=""
AllowAccessFromWebToFollowingIPAddresses=""
CreateDirDataIfNotExists=0
BuildHistoryFormat=text
BuildReportFormat=html
SaveDatabaseFilesWithPermissionsForEveryone=0
PurgeLogFile=0
KeepBackupOfHistoricFiles=0
DefaultFile="index.html"
SkipHosts=""
SkipUserAgents=""
SkipFiles=""
SkipReferrersBlackList=""
OnlyHosts=""
OnlyUserAgents=""
OnlyFiles=""
NotPageList="css js class gif jpg jpeg png bmp ico swf"
ValidHTTPCodes="200 304"
ValidSMTPCodes="1 250"
AuthenticatedUsersNotCaseSensitive=0
URLNotCaseSensitive=0
URLWithAnchor=0
URLQuerySeparators="?;"
URLWithQuery=0
URLWithQueryWithOnlyFollowingParameters=""
URLWithQueryWithoutFollowingParameters=""
URLReferrerWithQuery=0
WarningMessages=1
ErrorMessages=""
DebugMessages=0
NbOfLinesForCorruptedLog=50
WrapperScript=""
DecodeUA=0
LevelForBrowsersDetection=2
LevelForOSDetection=2
LevelForRefererAnalyze=2
LevelForRobotsDetection=2
LevelForSearchEnginesDetection=2
LevelForKeywordsDetection=2
LevelForFileTypesDetection=2
LevelForWormsDetection=0
_eof_

perl /websites/"$d"/webstats/tools/awstats_buildstaticpages.pl -awstatsprog=/websites/"$d"/webstats/wwwroot/cgi-bin/awstats.pl  -update -config="$tmp_name".sys.qualiproj.qualispace.com -dir=/websites/"$d"/web/awstats/

mv /websites/"$d"/web/awstats/awstats.$tmp_name.sys.qualiproj.qualispace.com.html /websites/"$d"/web/awstats/index.html

cron_awstatsupdate="/etc/cron.daily/awstatsupdate"

cat >> $cron_awstatsupdate <<  _eof_

###################cron_upadte for domain $d#######################
perl /websites/"$d"/webstats/tools/awstats_buildstaticpages.pl -awstatsprog=/websites/"$d"/webstats/wwwroot/cgi-bin/awstats.pl  -update -config="$tmp_name".sys.qualiproj.qualispace.com -dir=/websites/"$d"/web/awstats/

###############

script to delete directory protection - /htaccess

this script assumes the following
1) websites are located at /websites/domain.com
2) the vhost_config file is located at /usr/local/apache2/conf/extra/httpd_vhost.conf
3) all folder that you wish to directory protect are loated at /websites/domain.com/folder1/subfolder1
 
#!/bin/bash  
clear
read -p "Enter your domain: " d
read -p "Enter the directory that you want to delete: " f

if [ -d /websites/"$d" ]; then
  
   if [ -d /websites/"$d"/web/"$f" ]; then

      if [  -n "$(sed -n "/\#dir_protection_${d}_${f}#/,/&/p" /usr/local/apache2/conf/extra/httpd_vhost.conf)"  ]; then
sed -i "/\#dir_protection_${d}_${f}\#/,/\#dir_protection_${d}_${f}\#/d" /usr/local/apache2/conf/extra/httpd_vhost.conf
      else
echo -e "the directory  protection for folder /$f does not exist"
      fi
  else
echo -e "  the folder /$f does not exist"
   fi
else
echo -e "the Domain $d does not exist"
fi
--

script to set up entire website domain

 
 
#!/bin/bash
#steps to set up a website
echo -e " Enter you domain name "
read domain

domain_user=` echo $domain |sed s/\.com/com2631/g `
tmp_name=` echo $domain |sed s/\.com//g `
passwd_file=`cat /etc/passwd |grep $domain |sed s/:/\ /g |awk '{print $1}'`


if [ ! -d /websites/"$domain" ]; then

         if [ "$domain_user" != "$passwd_file" ]; then

useradd -d /websites/"$domain" -s /sbin/nologin "$domain_user"
echo -e " created domain $domain "

echo -e "adding ftp user "
read -p "Please enter the password for user $domain_user" p
(echo $p; echo $p ) | /usr/local/pureftpd/bin/pure-pw useradd "$domain_user" -f /usr/local/pureftpd/etc/pureftpd.passwd  -u "$domain_user" -d /websites/"$domain" -m
echo -e " adding user sucessful "

echo -e "creating directory structure "
mkdir /websites/"$domain"/web /websites/"$domain"/logs /websites/"$domain"/private /websites/"$domain"/data /websites/"$domain"/cgi-bin
echo -e "sucessfully created directory structure   "


echo -e " we chang the permission for the the $user "
chmod 711 /websites/"$domain"/ && chmod 711 /websites/"$domain"/*

echo -e " we change the ownership   for  the $domain "
chown "$user":"$user" /websites/"$domain" && chown "$user":"$user" /websites/"$domain"/*
echo -e " changes for $user was sucessful "


echo -e "Creating the Vhost directive domain $domain "

echo -e "
######################"$domain"2631###################

<VirtualHost 192.168.0.244:80>
ServerAdmin admin@"$tmp_name".sys.qualiproj.com
ServerName "$tmp_name".sys.qualiproj.qualispace.com
ServerAlias www."$tmp_name".sys.qualiproj.qualispace.com
DocumentRoot /websites/"$domain"/web
##############MIME_TYPE_"$domain"2631##################
<Directory /websites/"$domain"/web>
    Options -MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    AllowOverride FileInfo AuthConfig Limit
    Order allow,deny
    Allow from all
</Directory>
#################DIR_PROTECT_"$domain"2631###################
ErrorLog /websites/"$domain"/logs/"$tmp_name".sys.qualiproj.error_log
CustomLog /websites/"$domain"/logs/"$tmp_name".sys.qualiproj.access_log common
ScriptAlias /cgi-bin/ "/websites/"$domain"/cgi-bin/"
<Directory "/websites/"$domain"/cgi-bin">
        AllowOverride None
        Options +ExecCGI -Includes
       Order allow,deny
        Allow from all
</Directory>
</VirtualHost>
 " >>  /usr/local/apache2/conf/extra/httpd_vhost.conf

echo -e "Sucessfully created  the Vhost directive domain $domain "

echo -e " restarting httpd "
/etc/init.d/httpd graceful

echo -e "copying test html page to web folder "
cp -R /websites/agnello.com/web/bob.html /websites/"$domain"/web/index.html
echo -e "done "

echo -e " you can now log on to http://www."$tmp_name".sys.qualiproj.qualispace.com"
    else
echo -e "the user for this doamin already exist"
   fi
 else
echo -e  "the domin $domain already exist"
fi



--

script to add additional FTP user to a domain

This script does the following
 
ths scritp will only add additional FTP user to a domain
 
#!/bin/bash

#format
#script domain.com username foldername password sizeinMB

domain_system_user=`cat /etc/passwd | sed 's/:/ /g' |awk '{print $1  $5 }' |sed 's/\// /g' |awk '{print $3" "  }' |sed -n "/${1}/P" |sed 's/\./ /g' |awk '{print $1}' `

echo -e  "Chking if domin name exist "
if [ -d /websites/"$1" ]; then
echo -e "the domin exist"
echo -e "chking to see if user exist"
     if [ "`cat /usr/local/pureftpd/etc/pureftpd.passwd  | sed 's/:/ /g' |awk '{print $1  $5 }' |sed 's/\// /g' |awk '{print $3" " $1 }' |sed -n "/${1} ${2}/P"`" != "$1 $2"  ]; then

echo -e "chking to see if dir exist"
          if [ -d /websites/"$1"/"$3"  ]; then
echo -e "the dir $3 exist"
      echo -e "adding ftp user"
(echo $4; echo $4 ) | /usr/local/pureftpd/bin/pure-pw useradd "$2" -f /usr/local/pureftpd/etc/pureftpd.passwd  -u "$domain_system_user" -d /websites/"$1"/"$3"  -m

      else
echo -e "the dir $3 does not exist ===> the ftp user is not created"
           fi
    else
echo -e  "the user is all read present"
fi
else
echo -e "the domin does not exist"
fi



--

Other Articles

Enter your email address: