Useful Unix scripts


To display the details of available server CPU resources in UNIX

Display the number of CPUs in HP/UX

In HP/UX the ioscan command is used to display the number of processors available on the server.


root> ioscan -C processor | grep processor | wc -l
16

Display number of CPUs in Solaris


In Sun Solaris, the prsinfo command can be used to count the number of CPUs on the processor.

root> psrinfo -v|grep "Status of processor"|wc -l
       2
For details about the Solaris CPUs, the -v (verbose) option can be used with the psrinfo command

root> psrinfo -v

Status of processor 0 as of: 12/13/00 14:47:41
  Processor has been on-line since 11/05/00 13:26:42.
  The sparcv9 processor operates at 450 MHz,
  and has a sparcv9 floating point processor.
Status of processor 2 as of: 12/13/00 14:47:41
  Processor has been on-line since 11/05/00 13:26:43.
  The sparcv9 processor operates at 450 MHz,
  and has a sparcv9 floating point processor.

Display number of CPUs in Linux

To see the number of CPUs on a Linux server, you can cat the /proc/cpuinfo file.  In the example below we see that our Linux server has 4 CPUs.

root> cat /proc/cpuinfo|grep processor|wc -l
      4

Display number of CPUs in AIX

The lsdev command can be used to see the number of CPUs on an IBM AIX server.  Below we see that this AIX server has four CPUs:


root> lsdev -C|grep Process|wc -l


*********************************************************************************************************

To report the current CPU Activity

sar -u 1 5

sar utility can be used to provide various information about the server resources.

In the above example the parameters used and the details are as mentioned below
   -u option is for CPU related information
   1 is the frequency of execution of the command in seconds
   5 is the number of times the command should be executed.
   So the command displays the CPU information every 1 second for 5 times.


It reports the CPU related usage by the user(%usr), system(%sys), the CPU Wait for I/O(%wio) and the Idle Percentage(%idle).

Sample Output


14:08:17    %usr    %sys    %wio   %idle   physc
14:08:18      25        0          0           75       4.00
14:08:19      25        0          0           74       4.00
14:08:20      25        0          0           75       4.00
14:08:21      25        0          0           75       4.00
14:08:22      25        0          0           75       4.03
Average       25        0          0           75       4.01

Finding files in Unix based on specific criteria

FIND FILES THAT WERE MODIFIED/ACCESSED WITHIN A SPECIFIED TIME
       
   $   find  /<your path>  -mtime   1  -type   f
This command would return files modified  in the last 24 hours .
You can use -mtime option to return a list of files that were last modified N*24 hours ago. For example to find a file in last month (30 days) you would need to use -mtime +30 options.
-mtime +30   means you are looking for a file modified 30 days ago.
-mtime -30    means less than 30 days.
-mtime 30      If you skip + or - it means exactly 30 days
      -type f      searches only for files and not directories
To list the files in the directory tree that were modified within the past five minutes, type
$  find /<your path>  -mmin -5

To return a list of files that were accessed in the last 24 hours you would need to use the –atime option.
$  find  /<your path>   -atime   1  -type   f

******************************************************************
FINDING FILES WITH A SPECIFIC EXTENTION WITHIN A DIRECTORY
         $  find   /<your path>   -name  "*.cfg"
The command –name matches the file names with the specified pattern

******************************************************************
FINDING FILES BASED ON THE FILE-PERMISSIONS

Files with execute permission for group :
$ find /<your path>  -perm g=x   -type f
Files with execute permission for others:
$ find /<your path>  -perm  o=x   -type f
Where ‘g’ denotes groups and ‘o’ denotes others. x denotes execute permission.
******************************************************************
KILLING ACTIVE UNIX PROCESSES FOR SPECIFIC COMPONENTS

ps -ef |grep applmgr |grep <Component Name> |grep -v grep |awk '{print $2}' |xargs kill -9

For example to kill all active forms processes, we can use the following command:


ps -ef |grep applmgr |grep frm | grep -v grep |awk '{print $2}' |xargs kill -9

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.