Find command --
Find
-----
find / -xdev -size +1000000 -exec ls -ltr {} \; |sort -nr
find . -name core -exec rm {} \;
find /opt -type f -atime +60 -print
find /opt -size +100000 -exec ls -ltr {} \;
Cpu usage
---------
sar 1
sar -u 10 60
mpstat 10 60
/usr/ucb/ps aux
prstat -avm
1. Sar command
sar
sar -u 12 5 -->
sar -o <filename> 60 10
Type the following command to display per-processor statistics; 12 seconds apart; 5 times
# mpstat 12 5
You can also use traditional ps and top command:
# top
# ps -e -o pcpu -o pid -o user -o args
prtconf
This section shows the hardware architecture (Sun4u, which means that this is a Sun-4 system with an UltraSPARC CPU) and that it has 128MB of RAM.
# psrinfo
# psrinfo -p -
# psrinfo -pv
# psrinfo -v
# psrinfo
# psrinfo -v
# uname -a
# uname -X
$ isainfo -v
$ isainfo -b
$ isainfo -v
/etc/release - to diplay the contents about release
# cat /etc/release
#showrev
-a Prints all system revision information available.
-c (command) Prints the revision information about command.
-p Prints only the revision information about patches.
-R (root_path) Defines the full path name of a directory to use as the root_path.
-s (host name) Performs this operation on the specified host name.
-w Prints only the OpenWindows revision information
#showrev -a
$ showrev -a
hostid
$ hostid
$ prtconf -b
$ prtconf -vb
How to Display a System's Installed Memory
-----------------------------------------------------------------
To display the amount of memory that is installed on your system,
$ prtconf | grep Memory
$ psrinfo -p
$ psrinfo -pv
$ psrinfo -v
Date
----
# date mmddHHMM[[cc]yy]
mm Month, using two digits.
dd Day of the month, using two digits.
HH Hour, using two digits and a 24-hour clock.
MM Minutes, using two digits.
cc Century, using two digits.
yy Year, using two digits.
# date
# date 0121173404
How to setup a message of the day
-----------------------------------
/etc/motd
$ cat /etc/motd
Welcome to the UNIX Universe. Have a nice day.
default output
$ cat /etc/motd
Sun Microsystems Inc. SunOS 5.10 Generic May 2004
Crontab
----------
crontab files:
----------------
/var/spool/cron/crontabs
/etc/cron.d/cron.allow and
/etc/cron.d/cron.deny
Syntax of crontab File Entries
**********************************
Minute 0-59
Hour 0-23
Day of month 1-31
Month 1-12
Day of week 0-6 (0 = Sunday)
Create a new crontab file, or edit an existing file.
# crontab -e [username]
Verify your crontab file changes.
# crontab -l [username]
How to Verify That a crontab File Exists
#$ ls -l /var/spool/cron/crontabs
-rw-r--r-- 1 root sys 190 Feb 26 16:23 adm
-rw------- 1 root staff 225 Mar 1 9:19 jones
-rw-r--r-- 1 root root 1063 Feb 26 16:23 lp
-rw-r--r-- 1 root sys 441 Feb 26 16:25 root
-rw------- 1 root staff 60 Mar 1 9:15 smith
-rw-r--r-- 1 root sys 308 Feb 26 16:23 sys
How to Display a crontab File
----------------------------
$ crontab -l [username]
$ crontab -l
13 13 * * * chmod g+w /home1/documents/*.book > /dev/null 2>&1
Display the root crontab file
----------------------------
# crontab -l
How to Remove a crontab File
----------------------------$ crontab -r [username]
Verify that the crontab file has been removed.
----------------------------
# ls /var/spool/cron/crontabs
These access control files work together as follows:
* If cron.allow exists, only the users who are listed in this file can create, edit, display, or remove crontab files.
* If cron.allow does not exist, all users can submit crontab files, except for users who are listed in cron.deny.
* If neither cron.allow nor cron.deny exists, superuser privileges are required to run the crontab command.
1. Scheduling a Job For a Specific Time
----------------------------The basic usage of cron is to execute a job in a specific time as shown below. This will execute the Full backup shell script (full-backup) on 10th June 08:30 AM.
Please note that the time field uses 24 hours format. So, for 8 AM use 8, and for 8 PM use 20.
30 08 10 06 * /home/usr1/full-backup
30 – 30th Minute
08 – 08 AM
10 – 10th Day
06 – 6th Month (June)
* – Every day of the week
2. Schedule a Job For More Than One Instance (e.g. Twice a Day)
The following script take a incremental backup twice a day every day.
This example executes the specified incremental backup shell script (incremental-backup) at 11:00 and 16:00 on every day. The comma separated value in a field specifies that the command needs to be executed in all the mentioned time.
00 11,16 * * * /home/ramesh/bin/incremental-backup
00 – 0th Minute (Top of the hour)
11,16 – 11 AM and 4 PM
* – Every day
* – Every month
* – Every day of the week
3. Schedule a Job for Specific Range of Time (e.g. Only on Weekdays)
-----------------------------------------------------
If you wanted a job to be scheduled for every hour with in a specific range of time then use the following.
Cron Job everyday during working hours
This example checks the status of the database everyday (including weekends) during the working hours 9 a.m – 6 p.m
00 09-18 * * * /home/user1/bin/check-db-status
00 – 0th Minute (Top of the hour)
09-18 – 9 am, 10 am,11 am, 12 am, 1 pm, 2 pm, 3 pm, 4 pm, 5 pm, 6 pm
* – Every day
* – Every months
* – Every day of the week
Cron Job every weekday during working hours
-----------------------------------------------------
This example checks the status of the database every weekday (i.e excluding Sat and Sun) during the working hours 9 a.m – 6 p.m.
00 09-18 * * 1-5 /home/ramesh/bin/check-db-status
00 – 0th Minute (Top of the hour)
09-18 – 9 am, 10 am,11 am, 12 am, 1 pm, 2 pm, 3 pm, 4 pm, 5 pm, 6 pm
* – Every day
* – Every month
1-5 -Mon, Tue, Wed, Thu and Fri (Every Weekday)
6. Schedule a Job for Every Minute Using Cron.
-----------------------------------------------------
Ideally you may not have a requirement to schedule a job every minute. But understanding this example will will help you understand the other examples mentioned below in this article.
* * * * * CMD
The * means all the possible unit — i.e every minute of every hour through out the year. More than using this * directly, you will find it very useful in the following cases.
When you specify */5 in minute field means every 5 minutes.
When you specify 0-10/2 in minute field mean every 2 minutes in the first 10 minute.
Thus the above convention can be used for all the other 4 fields.
7. Schedule a Background Cron Job For Every 10 Minutes.
-----------------------------------------------------
Use the following, if you want to check the disk space every 10 minutes.
*/10 * * * * /home/ramesh/check-disk-space
Find
-----
find / -xdev -size +1000000 -exec ls -ltr {} \; |sort -nr
find . -name core -exec rm {} \;
find /opt -type f -atime +60 -print
find /opt -size +100000 -exec ls -ltr {} \;
Cpu usage
---------
sar 1
sar -u 10 60
mpstat 10 60
/usr/ucb/ps aux
prstat -avm
1. Sar command
sar
sar -u 12 5 -->
sar -o <filename> 60 10
Type the following command to display per-processor statistics; 12 seconds apart; 5 times
# mpstat 12 5
You can also use traditional ps and top command:
# top
# ps -e -o pcpu -o pid -o user -o args
prtconf
This section shows the hardware architecture (Sun4u, which means that this is a Sun-4 system with an UltraSPARC CPU) and that it has 128MB of RAM.
# psrinfo
# psrinfo -p -
# psrinfo -pv
# psrinfo -v
# psrinfo
# psrinfo -v
# uname -a
# uname -X
$ isainfo -v
$ isainfo -b
$ isainfo -v
/etc/release - to diplay the contents about release
# cat /etc/release
#showrev
-a Prints all system revision information available.
-c (command) Prints the revision information about command.
-p Prints only the revision information about patches.
-R (root_path) Defines the full path name of a directory to use as the root_path.
-s (host name) Performs this operation on the specified host name.
-w Prints only the OpenWindows revision information
#showrev -a
$ showrev -a
hostid
$ hostid
$ prtconf -b
$ prtconf -vb
How to Display a System's Installed Memory
-----------------------------------------------------------------
To display the amount of memory that is installed on your system,
$ prtconf | grep Memory
$ psrinfo -p
$ psrinfo -pv
$ psrinfo -v
Date
----
# date mmddHHMM[[cc]yy]
mm Month, using two digits.
dd Day of the month, using two digits.
HH Hour, using two digits and a 24-hour clock.
MM Minutes, using two digits.
cc Century, using two digits.
yy Year, using two digits.
# date
# date 0121173404
How to setup a message of the day
-----------------------------------
/etc/motd
$ cat /etc/motd
Welcome to the UNIX Universe. Have a nice day.
default output
$ cat /etc/motd
Sun Microsystems Inc. SunOS 5.10 Generic May 2004
Crontab
----------
crontab files:
----------------
/var/spool/cron/crontabs
/etc/cron.d/cron.allow and
/etc/cron.d/cron.deny
Syntax of crontab File Entries
**********************************
Minute 0-59
Hour 0-23
Day of month 1-31
Month 1-12
Day of week 0-6 (0 = Sunday)
Create a new crontab file, or edit an existing file.
# crontab -e [username]
Verify your crontab file changes.
# crontab -l [username]
How to Verify That a crontab File Exists
#$ ls -l /var/spool/cron/crontabs
-rw-r--r-- 1 root sys 190 Feb 26 16:23 adm
-rw------- 1 root staff 225 Mar 1 9:19 jones
-rw-r--r-- 1 root root 1063 Feb 26 16:23 lp
-rw-r--r-- 1 root sys 441 Feb 26 16:25 root
-rw------- 1 root staff 60 Mar 1 9:15 smith
-rw-r--r-- 1 root sys 308 Feb 26 16:23 sys
How to Display a crontab File
----------------------------
$ crontab -l [username]
$ crontab -l
13 13 * * * chmod g+w /home1/documents/*.book > /dev/null 2>&1
Display the root crontab file
----------------------------
# crontab -l
How to Remove a crontab File
----------------------------$ crontab -r [username]
Verify that the crontab file has been removed.
----------------------------
# ls /var/spool/cron/crontabs
These access control files work together as follows:
* If cron.allow exists, only the users who are listed in this file can create, edit, display, or remove crontab files.
* If cron.allow does not exist, all users can submit crontab files, except for users who are listed in cron.deny.
* If neither cron.allow nor cron.deny exists, superuser privileges are required to run the crontab command.
1. Scheduling a Job For a Specific Time
----------------------------The basic usage of cron is to execute a job in a specific time as shown below. This will execute the Full backup shell script (full-backup) on 10th June 08:30 AM.
Please note that the time field uses 24 hours format. So, for 8 AM use 8, and for 8 PM use 20.
30 08 10 06 * /home/usr1/full-backup
30 – 30th Minute
08 – 08 AM
10 – 10th Day
06 – 6th Month (June)
* – Every day of the week
2. Schedule a Job For More Than One Instance (e.g. Twice a Day)
The following script take a incremental backup twice a day every day.
This example executes the specified incremental backup shell script (incremental-backup) at 11:00 and 16:00 on every day. The comma separated value in a field specifies that the command needs to be executed in all the mentioned time.
00 11,16 * * * /home/ramesh/bin/incremental-backup
00 – 0th Minute (Top of the hour)
11,16 – 11 AM and 4 PM
* – Every day
* – Every month
* – Every day of the week
3. Schedule a Job for Specific Range of Time (e.g. Only on Weekdays)
-----------------------------------------------------
If you wanted a job to be scheduled for every hour with in a specific range of time then use the following.
Cron Job everyday during working hours
This example checks the status of the database everyday (including weekends) during the working hours 9 a.m – 6 p.m
00 09-18 * * * /home/user1/bin/check-db-status
00 – 0th Minute (Top of the hour)
09-18 – 9 am, 10 am,11 am, 12 am, 1 pm, 2 pm, 3 pm, 4 pm, 5 pm, 6 pm
* – Every day
* – Every months
* – Every day of the week
Cron Job every weekday during working hours
-----------------------------------------------------
This example checks the status of the database every weekday (i.e excluding Sat and Sun) during the working hours 9 a.m – 6 p.m.
00 09-18 * * 1-5 /home/ramesh/bin/check-db-status
00 – 0th Minute (Top of the hour)
09-18 – 9 am, 10 am,11 am, 12 am, 1 pm, 2 pm, 3 pm, 4 pm, 5 pm, 6 pm
* – Every day
* – Every month
1-5 -Mon, Tue, Wed, Thu and Fri (Every Weekday)
6. Schedule a Job for Every Minute Using Cron.
-----------------------------------------------------
Ideally you may not have a requirement to schedule a job every minute. But understanding this example will will help you understand the other examples mentioned below in this article.
* * * * * CMD
The * means all the possible unit — i.e every minute of every hour through out the year. More than using this * directly, you will find it very useful in the following cases.
When you specify */5 in minute field means every 5 minutes.
When you specify 0-10/2 in minute field mean every 2 minutes in the first 10 minute.
Thus the above convention can be used for all the other 4 fields.
7. Schedule a Background Cron Job For Every 10 Minutes.
-----------------------------------------------------
Use the following, if you want to check the disk space every 10 minutes.
*/10 * * * * /home/ramesh/check-disk-space