Script LINUX

How to Install Crontab in

yum install cronie -y

# crontab -l

-bash: crontab: command not found

# yum -y install cronie

#vi /etc/crontab 

OR

# crontab -e

crontab: no changes made to crontab

#    vi /etc/crontab

*/30 * * * * root /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -update -config=mail.worldcm.com -configdir=/etc/awstats

[root@mail ~]# crontab -e

                         vi /etc/crontab

1 11 * * * /root/bin/diskcheck.sh

54 23 * * * /root/bin/mail_usage.sh                                  [ Attach file Down Mail Script ] 

1 8 * * * /sbin/ntpdate -u bd.pool.ntp.org

0 0 1,15 * * /root/bin/backup_and_mail.sh

* 4 * * * chown -R amavis.amavis /var/clamav

* 4 * * * chown -R amavis.amavis /var/log/clamav/ #Change Permission

* 4 * * * chown -R amavis.amavis /var/run/clamav/ #Change Permission

* 4 * * * chown -R amavis.amavis /var/amavis/ #Change Permission                           [ Antivirus]

* * 15 * * echo > /var/amavis/amavis.log  #Delete Amavis Logs

* 2 * * * service clamd restart #Restart CLAMAV

* 3 * * * /usr/sbin/postsuper -r ALL #Re-queue mails   [Auto refresh mailQ]

---------------------------------

[root@mail ~]# crontab -e

* * 30 * * echo > /var/amavis/amavis.log

@hourly chown -R amavis.amavis /var/clamav

* 4 * * * chown -R amavis.amavis /var/log/clamav/

* 4 * * * chown -R amavis.amavis /var/run/clamav/

* 4 * * * chown -R amavis.amavis /var/amavis/

@weekly sa-update

@weekly chown -R amavis.amavis /var/clamav

@weekly yum -y update amavisd-new clamav clamav-devel* clamd spamassassin

@weekly freshclam -v

@weekly service clamd restart

@weekly service spamassassin restart

________________________________________

Mail /mailq/ Disk   reports

# cd /root/bin

Download: https://drive.google.com/drive/folders/0B8kTAu8SZaHwRlZPWmNjbkNrdVU?usp=sharing

chmod 755 /root/bin/mqueue.pl

chmod 755 /root/bin/mail_usage.sh

chmod 755 /root/bin/backup_and_mail.sh

[root@mail ~]# crontab -e

* 3 * * * /root/bin/mqueue.pl

0 9 * * * /root/bin/mail_usage.sh

* * 1 * * /root/bin/backup_and_mail.sh

1 8 * * * /sbin/ntpdate -u bd.pool.ntp.org

      ----------------------------------------------------------------------------------

How to set cron job for every 45 days

0 0 */45 * * php path/to/your/php/script

0 0 */45 * * /home/ramesh/backup.sh

                                                          

        ----------------------------------

[root@mail postfix]# crontab -l

1 11 * * * /root/bin/diskcheck.sh

54 23 * * * /root/bin/mail_usage.sh

1 8 * * * /sbin/ntpdate -u bd.pool.ntp.org                     

0 0 1,15 * * /root/bin/backup_and_mail.sh

------------------------------------------------------------------------------------

[root@mail postfix]# vi /etc/crontab

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

MAILTO=root

HOME=/

                                                                                                            [ Attach file Down Mail Script ] 

# run-parts   [ not use ]

01 * * * * root run-parts /etc/cron.hourly

02 4 * * * root run-parts /etc/cron.daily

22 4 * * 0 root run-parts /etc/cron.weekly

42 4 1 * * root run-parts /etc/cron.monthly

-----------------------------------------------------------------------------------

Bulk delete from Postfix queue [ delete-queue] script

Save the above script to a file say “delete-queue” in your home directory, and make it excutable:

# chmod 755 delete-queue                                          [ Script name  delete-queue   ATTACH Down] 

Usage

Delete all queued messages from or to the domain “spamdomain.com”

./delete-queue spamdomain.com

Delete all queued messages to specific address “bogususer@spamdomain.com”

./delete-queue bogususer@spamdomain.com

Delete all queued messages that begin with the word “bush” in the e-mail address:

./delete-queue bush*\@whateverdomain.com

Delete all queued messages that contain the word “abc” in the e-mail address:

./delete-queue abc

       ------------------

# postsuper -d ALL      [mail Q Delete]

To remove all mails sent by user@adminlogs.info from the queue :

mailq| grep '^[A-Z0-9]'|grep user@adminlogs.info|cut -f1 -d' ' |tr -d \*|postsuper -d -

To remove all mails being sent using the From address “user@adminlogs.info” :

#  mailq | awk '/^[0-9,A-F].*user@adminlogs.info / {print $1}' | cut -d '!' -f 1 | postsuper -d -

To remove all mails sent by the domain adminlogs.info from the queue :

#  mailq| grep '^[A-Z0-9]'|grep @adminlogs.info|cut -f1 -d' ' |tr -d \*|postsuper -d -

Disk Space

du -h --max-depth=1

Requeue mails in a mail queue:

# postsuper -r ALL

#postqueue -f

Mail ProbleM

#mailq                    [show Q mail]

Requeue mails in a mail queue:

# postsuper -r ALL

#postqueue -f

# postsuper -d ALL      [mail Q Delete]

# postsuper -d ALL deferred            [remove all mails in the deferred queue ]

------------------------------------------------------------------------------------

A Shell Script to Monitor Network, Disk Usage, Uptime, Load Average and RAM Usage in Linux

# wget http://tecmint.com/wp-content/scripts/tecmint_monitor.sh 

      OR - Attach file Under: tecmint_monitor.sh      [ pls Download ]

# chmod 755 tecmint_monitor.sh

To install "tecmint_monitor.sh" script, simple use -i (install) option as shown below.

#./tecmint_monitor.sh -i

# monitor

#chown almasud2:mail *

#chmod 660 *

#chown -R avinash:mail .Sent     [ if send mail error ]

After installation, you can run the script by calling command 'monitor' from any location or user. If you don’t like to install it, you need to include the location every-time you want to run it.

# ./Path/to/script/tecmint_monitor.sh

-----------------------------------------------------------------------------------------------

mb2md

# chmod 755 mb2md   [Download Under Script]

Inbox Mail Transfer( var/spool/mail   to mail Dir) command 

[root@mail ~]# ./mb2md -s /var/spool/mail/kamal -R -d /home/kamal/Maildir

Converting /var/spool/mail/kamal to maildir: /home/kamal/Maildir

Source Mbox is /var/spool/mail/kamal

Target Maildir is /home/nemo/Maildir

6 messages.

# cd /home

# chown -R kamal:kamal kamal

Inbox Mail Transfer

[root@mail ~]#./mb2md -s /home/mahbubhkhan/mail/Sent -R -d /home/mahbubhkhan/Maildir/.Sent/

                  -----------      X   X  X  X  X  X  --------------------

---------------------------------------------------------------------------------------------------------------------------------------

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

Total Mail Report

#yum -y install awstats

[root@mail conf.d]# vi /etc/httpd/conf.d/awstats.conf

#

# Directives to add to your Apache conf file to allow use of AWStats as a CGI.

# Note that path "/usr/share/awstats/" must reflect your AWStats install path.

#

Alias /awstatsclasses "/var/www/awstats/classes/"

Alias /awstatscss "/var/www/awstats/css/"

Alias /awstatsicons "/var/www/awstats/icon/"

ScriptAlias /awstats/ "/var/www/awstats/"

#

# This is to permit URL access to scripts/files in AWStats directory.

#

<Directory "/var/www/awstats">

    Options None

    AllowOverride None

    Order allow,deny

    Allow from 127.0.0.1 192.168.0.0/16 202.22.0.0/16 202.161.189.0/24

</Directory>

# Additional Perl modules

<IfModule mod_env.c>

    SetEnv PERL5LIB /var/www/awstats/lib:/var/www/awstats/plugins

</IfModule>

-----------------------------------------------------

OR  attach file under  wstats.conf

---------------------------------------------------------------

#wq

[root@ho ~]# vi /etc/awstats/awstats.mail.dbl-group.com.conf

pls download and copy pest  file -location: /etc/awstats/   (awstats.mail.dbl-group.com.conf)

#wq

Then run the script

/var/www/awstats/awstats.pl  -config=mail.dbl-group.com -update

Open web Browser

Link is:   http://mail.dbl-group.com/awstats/awstats.pl?config=mail.dbl-group.com

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

Startup Mail

#vi .bash_profile 

#cp  .bash_profile  .bash_profile.bk

#vi .bash_profile

File-open  ------       [ pest this line-.bash_profile]

# User specific environment and startup programs

unset USERNAME

echo 'ALERT - Root Shell Access on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1`" faruque.ahmed@abc.net mokbul.hossain@abc.net shakil.ahmed@abcl.net

#wq

                                              ----------------------------------

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

        . ~/.bashrc

fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

unset USERNAME

echo 'ALERT - Root Shell Access on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1`" system@abc.net

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

Simple Remove files older than XX

-this shell script will find files on a particular directory and remove older than the number of days specified. The file can be viewed/downloaded on this link

          ---------------------------------------------------------------

#!/bin/sh #Script to remove 23 days old logs #   /usr/bin/find /opt/FLT/tutorials/logs -type f -mtime +23 -exec rm {} \;

-----------------------------------------------------------------------------------------------

WEB:

https://www.arschkrebs.de/postfix/scripts/

https://github.com/strycore/scripts/blob/master/postfix-logparser.py