Automation with Cron

In every linux cron service we found and it is most familiar command to every system administrator. I am proud to be one of them.

CRON – Introduction :

The cron is a daemon and we can manage it with service names crond. Cron is the best solution in all sort of Linux Operating systems to run scritps,commands at a determined or specified time. So as I did mentioned it is a service it will start with system and do its running as long as system running.

Generally cron will executes commands or scripts in “sh” shell (/bin/sh) . If you want to run your script in a different shell dont forget mentioning it before executing the command.

Cron Configuration file will be called as cron table and we can invoke it with command named as “crontab”. Every user in linux have his/her own crontab and all users cron configurations will store at /var/spool/cron. All the cron jobs will be recorded at location /var/cron/log or /var/adm/cron/log.

CRON – Format :

Minute     Hour      DayofMonth      Month      Weekday     Command

Minute           Minute of the Hour         0 to 59
Hour               Hour Of the day             0 to 23
DOM              Day of month                 1 to 31
Month             Month of the yead          1 to 12
Weekday         Day of the week             0 to 6( 0 = Sunday)

In Cron scheduling if specific value not mentioned then automatically it will consider it for everytime. Unspecified part will have value as ‘*’. If particular field got particular value then it will executes at that time.Two integers separated by a dash mention like range. Range followed by a step value is nothing but period.Comma separated for all possibilities.

For Example:

1.        45 10 * * 1-5 echo ” hi ” > /dev/console

So 45 is Minute ,10 Hour, * for all & again * ,1-5 Range for weekday.

i.e Every Monday to Friday at time of 10:45 say “hi” and send to /dev/console.

2.         0,30 * 13 * 5 echo ” hi “

So 0,30 i.e at every 0 min ( starting sec of a min) and after 30 Min , * for hour i.e for all hours ,13th of month and * for every month and 5 of the week  i.e Friday.

So the above time saying like

Everymonth 13th and everymonth Friday at every half -n-hour execute echo “hi” command.

3.    20 1 * * * find /tmp -atime +3 -type f -exec rm -f { } ‘;’

20 for minute
1 for Hour

* for day of month means all days of month ( 1-30)
* for month means all month (1-12)
* for weekday means for all days of a week ( 0-6)

So Everyday,Everyweek, Every month at time of 1:20 execute that script or command. and command simple finding unused file in /tmp for 3 days and removing it.

4.  10 10 1-30/2  * * echo ” Hi”

command will execute at 10  hr :10  hr everymonth & everyweek but every odd date only.

NOTE: Cron have a small problem , that it wont load .profile or bashrc while executing commands , so if your script is have anything to do with environment variable you must have to mention it with in script.

CRON – Management :

crontab -e : To edit crontab
crontab -l : To list cron jobs
crontab -r : Remove all cron jobs

As I did mentioned every user have his own cron configuration file , root user can manage other user cron jobs with above commands. for example

crontab -e raja : edits raja crontab
crontab -l raja : list cron jobs of raja
crontab -r raja : removes cron jobs of raja

System administrators have a choice like which user allowed to do cron jobs and which are not.

If username exists in cron.deny then he wont be allowed for cron automation and if he does in cron.allow. In Linux by default all are allowed , so you can use cron.deny to block particular user for cron. But HP Linux only root user allowed by default and everyuser must be in cron.allow if we have ti allow cron and same for cron.deny to block.

Location : /etc


Almost all Linux’s have cron pre installed and have some crontab entries too which are pre installed.

/etc/cron.daily – all scripts in /etc/cron.daily  will execute scripts once a day.
/etc/cron.weekly – here scripts will run once per a week.

I hope it will help you to understand a little bit about cron. If you know advanced than this please let me know.

Help Helps You.



How to remove Shutdown,restart options from startmenu in windows server 2008.

1. Open run
2.Type gpedit.msc
3.choose User Configuration -> Administrative Templates -> Start menu & Task Bar

Choose Remove and prevent access to the Shut Down, Restart, Sleep, and Hibernate commands

and open it and select enabled.


see whether it is updated or not. If its not updated then open run and type as

gpupdate /force

and now shutdown,restart removed from start menu.

Basic MySQL Administration

1. How to create a user and along with his privileges automatically ?

GRANT ALL PRIVILEGES ON database.* To ‘username’@’hosr or IP ‘ IDENTIFIED BY ‘password’;
flush privileges;

2. How to give only specific privileges to users ?

GRANT select,lock tables ON *.* To ‘user’@’host or IP ‘ IDENTIFIED BY ‘password’;
flush privileges;

3. How to see permissions of a user ?

show grants for ‘username’@’hostanme’;

4. How to revoke all given privileges ?

revoke all privileges on *.* from ‘user’@’host’;

5. How to take backup of database ?

mysqldump –user –password= databasename > databasebackup.sql

6. How to take backup of two databases ?

mysqldump –user –password= databasename1 databasename2 > databasebackup.sql

7. How to take backup of all databases in MySQL ?

mysqldump –user –password= -all-databases alldbbackup.sql

8. How to take backup of table in database ?

mysqldump –user –password= database_name database_table \   databasebackup.sql 

9. How to restore one database ?

mysql –user –password= databasename < databasebackup.sql
mysql_upgrade -p -u root –force

Reset root password in CentOS 6

In CentOS base version , I mean v6 there is a bug and you cant reset the password in the usual way. I am going to mention both the ways.

To reset root password of CentOS machine, Start your PC. You will get GRUB screen and there choose ” e” to edit booting kernel. After that It will open in a new window with current configuration.

If you observe there you can find a line with two last words like  ” rhgb quiet \” Dont worry about “\” , use backspace and remove ” rghb quiet”. Then add in that line as ” a 1 ” and then press F10 key to boot. it will successfully boot into /bin/sh and there by using passwd command you can reset the root  password of the server.

If its not working .

1 . SELinux may be causing the problem , to take care of it you have to restart Machine and again edit GRUB , but this time we have to one more parameter extra.

Now add parameters like ” a selinux=0 1 ” , So CentOS will boot into /bin/sh with permissive mode of selinux.

2. Authentication Token manipulation error

Simple , the root partition has mounted as read-only so you are unable to write( password update -new password writing ) anything to root directory. so you have to remount it with read-write access & of course you are a root user .

mount -o remount, rw /

So after that try again with passwd command to reset the password.

Hope it helps.

CentOS 7 Repositories

table.curvedEdges { border:10px solid RoyalBlue;-webkit-border-radius:13px;-moz-border-radius:13px;-ms-border-radius:13px;-o-border-radius:13px;border-radius:13px; } table.curvedEdges td, table.curvedEdges th { border-bottom:1px dotted black;padding:5px; } <!– Be sure to place the above styles (i.e. everything between the tags) into the document ‘head’ (i.e. between the tags. Everything below goes inside the tags) –>

EPEL for CentOS 7
## RHEL/CentOS 7 64-Bit ##
# wget
# rpm -ivh epel-release-7-0.2.noarch.rpm
RPMForge for CentOS 7
sudo rpm –import
sudo yum install

Remi for CentOS 7
sudo rpm -Uvh
sudo sed -i ‘s/enabled=0/enabled=1/g’ /etc/yum.repos.d/remi.repo

Note: Didnt get full information about RPM Fusion , if anybody get it let me know.

Explanation of /etc/fstab

What is fstab file?

fstab is a configuration file that contains information of all the partitions and storage devices in your computer. The file is located under 
/etc, so the full path to this file is /etc/fstab.

/etc/fstab contains information of where your partitions and storage devices should be mounted and how. If you can’t access your Windows partition from Linux, aren’t able to mount your CD or write to your floppy as a normal user, or have problems with your CD-RW, you probably have a misconfigured /etc/fstab file. So, you can usually fix your mounting problems by editing your fstab file.

/etc/fstab is just a plain text file, so you can open and edit it with any text editor you’re familiar with. However, note that you must have the root privileges before editing fstab. So, in order to edit the file, you must either log in as root or use the su command to become root.

Sample fstab file looks like this
Note that this system has two IDE partitions, one which is used as /, and the other used as /home. It also has two DOS partitions which are mounted under /mnt. Note the user option provided for the cdrom, and the floppy drive. This is one of the many default parameters you can specify. In this case it means that any user can mount a cdrom, or floppy disk. Other options will be dealt with later.

fstab file format explination

fstab consists of a number of lines (one for each filesystem) seperated into six fields. Each field is seperated from the next by whitespace (spaces/tabs).

So from the example given previously:

/dev/hdc /mnt/cdrom iso9660 noauto,ro,user 0 0

 first field (/dev/hdc) is the physical device/remote filesystem which is to be described.

 second field (/mnt/cdrom) specifies the mount point where the filesystem will be mounted.

 third field (iso9660) is the type of filesystem on the device from the first field.

 fourth field (noauto,ro,user) is a (default) list of options which mount should use when mounting the filesystem.

 fifth field (0) is used by dump (a backup utility) to decide if a filesystem should be backed up. If zero then dump will ignore that filesystem. The sixth field (0) is used by fsck (the filesystem check utility) to determine the order in which filesystems should be checked.

If zero then fsck won’t check the filesystem.
(as the example line above is a cdrom there is very little point in doing a fsck on it, so the value is zero).

File system mount options

As the filesystems in /etc/fstab will eventually be mounted using mount(8) it isn’t surprising that the options field simply contains a comma-seperated list of options which will be passed directly to mount when it tries to mount the filesystem.

The options common to all filesystems are:

sync / async
All I/O to the file system should be done (a)synchronously.
The filesystem can be mounted automatically (at bootup, or when mount is passed the -a option). This is really unnecessary as this is the default action of mount -a anyway.
The filesystem will NOT be automatically mounted at startup, or when mount passed -a. You must explicitly mount the filesystem.
dev / nodev
Permit any user to mount the filesyste. This automatically implies noexec,
exec / noexec
Permit/Prevent the execution of binaries from the filesystem.
suid / nosuid
Permit/Block the operation of suid, and sgid bits.
Mount read-only.
Mount read-write.
Permit any user to mount the filesystem. This automatically implies noexec, nosuid,nodev unless overridden.
Only permit root to mount the filesystem. This is also a default setting.
Use default settings. Equivalent to rw,suid,dev,exec,auto,nouser,async.
There are numerous options for the specific filesystes supported by mount.
However these are some of the more useful, for the full list check out the man page for `mount`.
check={none, normal, strict}
Sets the fsck checking level.
print debugging info on each remount.
n is the block which should be used as the superblock for the fs.
check={r[elaxed], n[ormal], s[trict]}
Not the same as ext2. Rather deals with allowed filenames. See mount man page.
conv={b[inary], t[ext], a[uto]}
Performs DOSUNIX text file conversions automatically. See mount man page.
uid=n, gid=n
Disables Rock Ridge extensions.

fstab file Supported file systems list

affs – I have know idea what this is, if anyone else does please enlighten me.


ext – Don’t use this. ext has been superseded by ext2.

ext2 – The standard Linux filesystem. (NB, this has nothing to do with extended partitions.)

fat – DOS.

hpfs – OS/2 High Performance File System.

iso9660 – CD-ROM’s. Supports Rock Ridge extensions by default.

minix – can be useful for floppy disks.

msdos – Just fat with some addtional error checking.

nfs – Network FileSystem. Dealt with later.

proc – The process psudeo-filesystem now standard in Linux.

smb – Another network filesystem. Compatable with WFW, and NT. See Samba.

ufs – Unix FileSystem.

unsdos – Unix filesystem on a FAT partition.

vfat – MS’s kludge of FAT to provide long filenames.