Monday, May 30, 2011

Upgrading JDK to latest version

Below given is a self-explanatory example for upgrading JDK from version 1.4.2 to 1.6.0_25.


[root@host01-d1 ~/]# java -version
java version "1.4.2"
gij (GNU libgcj) version 4.1.2 20080704 (Red Hat 4.1.2-46)

Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@host01-d1 ~]# alternatives --config java

There is 1 program that provides 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java

Enter to keep the current selection[+], or type selection number:
[root@host01-d1 ~]# alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_25/bin/java 2
[root@host01-d1 ~]#
[root@host01-d1 ~]# alternatives --install /usr/bin/javac javac /usr/java/jdk1.6.0_25/bin/javac 2
[root@host01-d1 ~]# alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
   2           /usr/java/jdk1.6.0_25/bin/java

Enter to keep the current selection[+], or type selection number: 2
[root@host01-d1 ~]# alternatives --config javac

There are 2 programs which provide 'javac'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/java-1.4.2-gcj/bin/javac
   2           /usr/java/jdk1.6.0_25/bin/javac

Enter to keep the current selection[+], or type selection number: 2
[root@host01-d1 ~]# java -version
java version "1.6.0_25"
Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode)


[root@host01-d1 ~]# which javac
/usr/bin/javac
[root@host01-d1 ~]# which java
/usr/bin/java
[root@host01-d1 ~]# /usr/bin/java -version
java version "1.6.0_25"
Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode)
[root@host01-d1 ~]# which javac
/usr/bin/javac
[root@host01-d1 ~]# ls -l /usr/bin/javac
lrwxrwxrwx 1 root root 23 May 25 00:24 /usr/bin/javac -> /etc/alternatives/javac
[root@host01-d1 ~]# ls -l /etc/alternatives/javac
lrwxrwxrwx 1 root root 31 May 25 15:26 /etc/alternatives/javac -> /usr/java/jdk1.6.0_25/bin/javac
[root@host01-d1 ~]#

Tuesday, May 17, 2011

Steps to create and mount ext4 filesystem

Syntax: 

mkfs.ext4  "Device Name"

(or)

mke2fs -t ext4 "Device Name"


Example:
[root@hostxyz bin]# mkfs.ext4 /dev/sda3

mke4fs 1.41.9 (22-Aug-2009)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
67108864 inodes, 268435456 blocks
13421772 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
8192 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000, 214990848

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

[root@hostxyz ~]# mkdir /ext4_filesystem

[root@hostxyz ~]# mount -t ext4 /dev/sda3  /ext4_filesystem


[root@hostxyz ~]# file -sL /dev/sda3
/dev/sda3: Linux rev 1.0 ext4 filesystem data (needs journal recovery) (extents) (large files) (huge files)
[root@hostxyz ~]#

Note: Ext4 filesystem is available starting from Kernel 2.6.19. Incase your server don't have the "ext4" package installed, you can avail it by installing the latest version of "e4fsprogs" rpm.
(URL to download for CentOS: http://pkgs.org/package/e4fsprogs ).
However it is recommended to use the Ext4 filesystem from the kernel version mentioned above to get the full advantage of it.

Saturday, March 19, 2011

Killing multiple processes at once in Linux

Requirement 1:  Kill all the running processes owned by a particular user.

List all the Process IDs of user
# pgrep -u <username>         

Find Real UID of user
# id <username>

Kill all the processes owned by user with Real UID specified.
# pkill -U <Real UID>           

Example:
Killing all the processes owned by userid 'nagios'

# pgrep -u nagios

# id nagios 
   uid=510(nagios) gid=510(nagios) groups=510(nagios)

# pkill –U 510


Requirement 2:  Kill all processes that are running with some process-name or string (from ps output)

Using "For" loop:
[root@hostxyz ~]# for i in `ps -ef | grep -v grep | grep [username/some string] | awk '{print $2}'`; do kill -9 $i; echo “process id $i is killed”; done

Using "Xargs":
[root@hostxyz ~]# ps aux | grep -v grep | grep [username/some string] | awk '{print $2}' | xargs kill -9

Sample execution:  
To kill all processes that has string "jboss" in it 

[root@hostxyz ~]# for i in `ps -ef | grep -v grep | grep jboss | awk '{print $2}'`; do kill -9 $i; echo "Process id $i is killed"; done

[root@hostxyz ~]# ps aux | grep -v grep | grep jboss | awk '{print $2} | xargs kill -9


Thursday, March 10, 2011

Enabling/Disabling CPUs in Linux

We could get into situation to either disable or enable one or more CPU on a running Linux server (without reboot) and the Linux kernel does support that feature. The reason could be for improving the performance of server or for saving some computing power.


To check the list of CPUs available:


[root@hostxyz ]# cat /proc/cpuinfo


[root@hostxyz ~]# cd /sys/devices/system/cpu
[root@hostxyz cpu]# pwd
/sys/devices/system/cpu
[root@hostxyz cpu]# ls -l
total 0
drwxr-xr-x 4 root root    0 Mar  6 00:30 cpu0
drwxr-xr-x 4 root root    0 Mar  6 00:30 cpu1
drwxr-xr-x 4 root root    0 Mar  6 00:30 cpu2
drwxr-xr-x 4 root root    0 Mar  6 00:30 cpu3
drwxr-xr-x 4 root root    0 Mar  6 00:30 cpu4
drwxr-xr-x 4 root root    0 Mar  6 00:30 cpu5
drwxr-xr-x 4 root root    0 Mar  6 00:30 cpu6
drwxr-xr-x 4 root root    0 Mar  6 00:30 cpu7
-rw-r--r-- 1 root root 4096 Mar  6 00:30 sched_mc_power_savings
[root@hostxyz cpu]#


Suppose I want to disable the CPU no 5:

[root@hostxyz cpu]# cd cpu5
[root@hostxyz cpu5]# ls
cache  crash_notes  online  topology
[root@hostxyz cpu5]# cat online
1
[root@hostxyz cpu5]# echo 0 > online
[root@hostxyz cpu5]# cat /proc/cpuinfo | grep -i 'Processor'
processor       : 0
processor       : 1
processor       : 2
processor       : 3
processor       : 4                             
processor       : 6
processor       : 7
[root@hostxyz cpu5]#
[root@hostxyz cpu5]# cat /proc/interrupts
           CPU0       CPU1       CPU2       CPU3       CPU4       CPU6       CPU7
  0:  346882565          0          0          0          0          0          0    IO-APIC-edge  timer
  1:          0          0          0          0          0          0          0    IO-APIC-edge  i8042
  8:          0          0          0          0          0          0          0    IO-APIC-edge  rtc
  9:          0          0          0          0          0          0          0   IO-APIC-level  acpi
 14:          0          0          0          0          0          0          0    IO-APIC-edge  ata_piix
 15:          0          0          0          0          0          0          0    IO-APIC-edge  ata_piix
 66:         19          0          0          0          0          0          0   IO-APIC-level  ehci_hcd:usb1
 74:          0          0          0          0          0          0          0   IO-APIC-level  uhci_hcd:usb2
 82:         49          0          0          0          0          0          0   IO-APIC-level  uhci_hcd:usb3
 90:          0          0          0          0          0          0          0   IO-APIC-level  uhci_hcd:usb4
 98:       1647        431          0     380368          0         53          0   IO-APIC-level  lpfc
106:       1667         53          0     380346          0        374          0   IO-APIC-level  lpfc
122:    3359627          0          0          0          0          0          0         PCI-MSI  eth0
169:       4954       4701          0     404864          0          0          0   IO-APIC-level  ioc0
NMI:       4505       2316       2389       2332       2882       2164       2909
LOC:  339979108  339988403  339978966  339984061  339983989  339992274  339992202
ERR:          0
MIS:          0
[root@hostxyz cpu5]#


In the above /proc output, you could see the CPU5 has gone !!!!!!!!!


[root@hostxyz cpu5]# cat online
0

Enabling the CPU 5 back:

[root@hostxyz cpu5]# echo 1 > online
[root@hostxyz cpu5]# cat /proc/cpuinfo | grep -i 'Processor'
processor       : 0
processor       : 1
processor       : 2
processor       : 3
processor       : 4
processor       : 5
processor       : 6
processor       : 7
[root@hostxyz cpu5]#
[root@hostxyz cpu5]# cat /proc/interrupts
           CPU0       CPU1       CPU2       CPU3       CPU4       CPU5       CPU6       CPU7
  0:  346920869          0          0          0          0          0          0          0    IO-APIC-edge  timer
  1:          0          0          0          0          0          0          0          0    IO-APIC-edge  i8042
  8:          0          0          0          0          0          0          0          0    IO-APIC-edge  rtc
  9:          0          0          0          0          0          0          0          0   IO-APIC-level  acpi
 14:          0          0          0          0          0          0          0          0    IO-APIC-edge  ata_piix
 15:          0          0          0          0          0          0          0          0    IO-APIC-edge  ata_piix
 66:         19          0          0          0          0          0          0          0   IO-APIC-level  ehci_hcd:usb1
 74:          0          0          0          0          0          0          0          0   IO-APIC-level  uhci_hcd:usb2
 82:         49          0          0          0          0          0          0          0   IO-APIC-level  uhci_hcd:usb3
 90:          0          0          0          0          0          0          0          0   IO-APIC-level  uhci_hcd:usb4
 98:       1647        431          0     380412          0          0         53          0   IO-APIC-level  lpfc
106:       1667         53          0     380390          0          0        374          0   IO-APIC-level  lpfc
122:    3360061          0          0          0          0          0          0          0         PCI-MSI  eth0
169:       4954       4703          0     404921          0          0          0          0   IO-APIC-level  ioc0
NMI:       4505       2317       2389       2332       2883       2428       2164       2910
LOC:  340016644  340025946  340016502  340021607  340021535  339927925  340029818  340029746
ERR:          0
MIS:          0
[root@hostxyz cpu5]#

In the above /proc output, you can see that I brought back the CPU 5 back.

Wednesday, March 9, 2011

All about TIME in Linux

Below given are some useful commands pertaining to Time and Date:

[root@hostxyz ]# clock --show
Tue 08 Mar 2011 02:27:07 PM CST  -0.950788 seconds

[root@hostxyz ]# hwclock
Tue 08 Mar 2011 02:27:17 PM CST  -0.438789 seconds
[root@hostxyz ]#

Set the hardware clock by executing:
# /sbin/hwclock --systohc
Syncing the time with other or Internet Time servers:
# /usr/bin/rdate -s  <remote server ip/hostname>
Syncing the time with NTP server:
# ntpdate -u <NTP server IP/Hostname>
 
Use "time" command to find the time of execution of a command:
[root@hostxyz ]# time updatedb
real    0m13.759s
user    0m0.293s
sys     0m1.190s
[root@hostxyz ]# times updatedb
0m0.044s 0m0.029s
0m3.839s 0m1.830s
[root@hostxyz ]#
# Timezone config file
[root@hostxyz ]# cat /etc/sysconfig/clock
ZONE="America/Chicago"
UTC=true
ARC=false
[root@hostxyz ]#
If you wish the Change the Timezone to IST, follow the below steps:
# rm -rf  /etc/localtime
Change to the directory /usr/share/zoneinfo here you will find a list of time zone regions. Choose the most appropriate region, if you live in India in city Chennai, you will find a directory "Indian".
Create a symbolic link to the appropriate timezone to /etc/localtime
# ln -sf /usr/share/zoneinfo/Indian/Chennai /etc/localtime 
[root@hostxyz zoneinfo]# cat zone.tab | grep -w Indian
CC    -1210+09655       Indian/Cocos
CX    -1025+10543       Indian/Christmas
IO    -0720+07225       Indian/Chagos
KM    -1141+04316       Indian/Chennai
MG    -1855+04731       Indian/Antananarivo
MU    -2010+05730       Indian/Mauritius
MV    +0410+07330       Indian/Maldives
RE    -2052+05528       Indian/Reunion
SC    -0440+05528       Indian/Mahe
TF    -492110+0701303   Indian/Kerguelen
YT    -1247+04514       Indian/Mayotte
[root@hostxyz zoneinfo]#

Monday, March 7, 2011

Steps to upgrade openssh package


1st Method

1.  Download the latest openssh package from http://www.openssh.org/ under /usr/local.
2.  Extract the package: # tar -xvf openssh-<version>.tar.gz
3.  Take a note of current SSH installation on the server by executing the following commands:
      # which ssh
      # rpm -qa | grep ssh
      # rpm -qf  `which ssh` 
      Also take a backup of /etc/ssh folder.
4.  Go to /usr/local/openssh-<version no>/ 
5.  Compile the openssh package as follows:
     # ./configure --with-kerberos5 --with-pam --with-md5-passwords 
6. make 
7. make install 
8. Check if the system is using the newly compiled openssh package by running the 'which' and 'ssh -v' command. 
9. Manually link the older version of  'ssh' command to new version:
   # mv /usr/sbin/ssh /usr/sbin/ssh_old
   # ln -s /usr/local/bin/ssh /usr/sbin/ssh  


2nd Method (by overriding existing SSH config)
1.  Download the latest openssh package from http://www.openssh.org/ under /usr/local.
2.  Extract the package: # tar -xvf openssh-<version>.tar.gz
3.  Take a note of current SSH installation on the server by executing the following commands:
      # which ssh
      # rpm -qa | grep ssh
      # rpm -qf  `which ssh` 
      Also take a backup of /etc/ssh folder.
4.  Go to /usr/local/openssh-<version no>/ 
5.  Compile the openssh package as follows:

./configure --prefix=/usr --sysconfdir=/etc/ssh --with-ssl-dir=/opt/openssl-0.9.8e --with-pam  --with-kerberos5 --with-md5-passwords --with-tcp-wrappers

6. make 
7. make install 
8. Check if the system is using the newly compiled openssh package by running the 'which' and 'ssh -v' command. 


Saturday, March 5, 2011

Using 'date' command smartly

Here I have shown some examples for using 'date' command in various forms. This will be helpful for deriving some logic in scripting.


Current time:
[root@hostxyz ~]# date
Fri Mar  4 12:37:29 CST 2011


Output only the day of week:
[root@hostxyz ~]# date +%a
Fri


Output the Time 1 hour before:
[root@hostxyz ~]# date +%Y%m%d%H%M%S -d  "1 hour ago"
20110304113732
[root@hostxyz ~]#


Output the Time 2 hours before:
[root@hostxyz ~]# date   --date='2 hour ago' +'%b %e %H:'
Mar  4 10:
[root@hostxyz ~]#


Finding Yesterday's day and assigning to a variable DAY_1:  
DAY_1=`(date --date='1 days ago' '+&#37;a')`
echo $DAY_1


Finding day for two days ago and assigning to a variable DAY_2:
DAY_2=`(date --date='2 days ago' '+%a')`
echo $DAY_2



Monday, January 10, 2011

Suspending and resuming a running process in Linux

In Linux, a running process or command execution can be stopped in one terminal and made it to run from other terminal.  Let say you triggered a cp command for copying some huge volumes of data from one filesystem to other, from your own workstation. After initiating the command you realized that it would take more time to complete. In this situation, you got to deal with 2 issues. One is, incase you lost the connection to server, the command execution will stop, and other one is that you have to keep your workstation connected until the command execution completes.

Solution:

1.   Making the job to run in back-ground is a simple solution but it is not always possible to do it, when your script/command needs some set of inputs. Syntax for making a command execution to run in the back-ground is as follows:  # nohup  <command set> &     
(e.g   # nohup cp -apR /somefolder  /otherfolder & ).

2.   Start the job on first terminal (say Terminal-A). Open another terminal (say Terminal-B) where you can run the job uninterruptedly. On Terminal-B find out the Parent Process ID (PPID) of the Job which you started on Terminal-A. 
Execute the kill command with signal 19 to Suspend the process  
             # kill -19 <PID>
Go to Terminal-A and press Ctrl+z
Then come back to Terminal-B and execute the kill command with signal 18 to Continue the process
            # kill -18 <PID>
Exit from Terminal-A by running ‘exit’ command, Now your job/process will continue to run on Terminal-B.

Note: Please ensure that you suspend the PPID (Parent PID) of the Job (not the PID of its child process).  If you suspend the PID of child process and exit from Terminal-A, the parent process will get hang-up signal and terminate the execution, and the PID which you suspended will become defunct process.

Sunday, January 2, 2011

Monitoring command execution at regular intervals

I use these 2 methods to monitor command execution at regular intervals. One by using the command “watch” and another by using a small while statement.


Using watch command:
 # watch -n <time interval in seconds>  “command” or just  # watch  “command”


Examples:
# watch -n 10 "cat /proc/meminfo | grep -i Mem"      <- Watch Memory utilization at 10 seconds intervals
# watch -n 15 10 “du -sh |  grep /somefilesystem”     <- Watch disk utilization at 15 seconds interval.
# watch "ps aux|grep jboss"                                     <- Watch jboss process with default time interval


Using while statement:
while true; do <commands separated by semicolon>; sleep <time interval in seconds>; done  


Examples:

[adevaraju@hostxyz ~]$ while true; do cat /proc/meminfo | grep -i mem; uptime; echo; sleep 10; done
MemTotal:      4194480 kB
MemFree:         36776 kB
 01:52:51 up 14 days,  9:07,  1 user,  load average: 0.00, 0.00, 0.00


MemTotal:      4194480 kB
MemFree:         36652 kB
 01:53:01 up 14 days,  9:07,  1 user,  load average: 0.00, 0.00, 0.00


MemTotal:      4194480 kB
MemFree:         36776 kB
 01:53:11 up 14 days,  9:07,  1 user,  load average: 0.00, 0.00, 0.00


# while true; do echo Current time is  `date "+%H Hour: %M Minutes: %S Seconds"`; sleep 4; done
Current time is 01 Hour: 47 Minutes: 26 Seconds
Current time is 01 Hour: 47 Minutes: 30 Seconds
Current time is 01 Hour: 47 Minutes: 34 Seconds
Current time is 01 Hour: 47 Minutes: 38 Seconds
Current time is 01 Hour: 47 Minutes: 42 Seconds
Current time is 01 Hour: 47 Minutes: 46 Seconds
Current time is 01 Hour: 47 Minutes: 50 Seconds
Current time is 01 Hour: 47 Minutes: 54 Seconds
Current time is 01 Hour: 47 Minutes: 58 Seconds
Current time is 01 Hour: 48 Minutes: 02 Seconds
Current time is 01 Hour: 48 Minutes: 06 Seconds
#
PS:  “watch” command wouldn’t work properly if the command sets are complex. It will just display the result of first iteration and stay there forever.

Tuesday, December 28, 2010

Executing cronjobs on specific days in a month

You can use this post as a reference to schedule the Cronjobs in more Granular fashion.

Situation:
We had a requirement to execute couple of scripts on specific Saturdays of a month throughout the year  i.e., First script (say /opt/firstscript.sh) should be executed on all Saturdays EXCEPT first Saturday of the month, and the Second script (say /opt/secondscript.sh) should be executed ONLY on first Saturday of the month. This we required to do for scheduling Weekly Tape backups.

Executing a script on all Saturdays is fairly simple, we need to just specify number 6 on 5th column on crontab entry, but here the scenario is different.
The solution for this is shown below. This uses ‘date’ command to check if the current date is a first Saturday of a month.

0  2  *  *  6     [ $(date +%d) -gt 7 ]  && /opt/firstscript.sh               
# Executes at 2am on all Saturdays Except the first Saturday of the month (Saturdays other than 1st  can fall only after 7th ).

0  22  *  *  6   [ $(date +%d) -le 7 ]  && /opt/secondscript.sh        
# Executed at 10 PM ONLY on first Saturday of the month (A first Saturday can either be 7th or less than that ).

Thursday, December 23, 2010

Checking NFS and SAMBA shares

NFS

How to check the NFS shares available from a NFS Client ?
#  showmount -e <NFS Server IP>

Example
[root@hostxyz /]# showmount -e nfsserver.domain.com
Export list for nfsserver.domain.com:
/VOL0           stoash01-d3,staat01-d3,rdbash01,10.20.23.16,10.20.64.31,10.100.14.96 ,10.100.16.12 
/VOL1           (everyone)
/ORAAPPS        (everyone)
/ret_vol3       (everyone)
/nas_server_bkp (everyone)
/testnfs        (everyone)
[root@hostxyz /]#


From NFS server, how to find the list of NFS clients accessing the NFS share currently ?

Execute the following script:
for i in `cat /var/lib/nfs/rmtab | awk -F":" '{print $1}' | sort -u`; do nslookup $i | tail -2 | awk '{print $4}'; done

---------------------------------------------------------------------------------------------------------------------------------------------------------
SAMBA

How to find the list of Samba shares available from a Windows Server?

# smbclient -L Samba server IP –Uusername
Password:


[root@hostxyz /]# smbclient -L windows.tcprod.com -Uadevaraju
Password:
Domain=[TCPROD] OS=[Windows Server 2003 R2 3790 Service Pack 2] Server=[Windows Server 2003 R2 5.2]

        Sharename       Type      Comment
        ---------       ----      -------
        IPC$            IPC       Remote IPC
        sqldb_htk       Disk
        webash01-dev    Disk
        C$              Disk      Default share
        VOL3            Disk
        testsmb         Disk
        SMBSYSENG       Disk
        HPUniver.3      Printer   HP Universal Printing PS
        HPUniver.2      Printer   HP Universal Printing PCL 5
        ADMIN$          Disk      Remote Admin
        HPUniver        Printer   HP Universal Printing PCL 6
        print$          Disk      Printer Drivers
        F$              Disk      Default share
        nas_server_bkp  Disk
        SMBVOL1         Disk
        windowsprodbackup Disk
        SMBVOL0         Disk
        Report_server_bkp Disk
        E$              Disk      Default share
        exchange_db     Disk
        sysengdata      Disk


How to mount a Windows Share on to a Linux mount point:


Syntax: 
Put this entry in /etc/fstab and do 'mount -a'
//Windows server IP/Sambashare  /Linux_mount cifs username=XXX,password=XXXX 0 0


Example:
//Windows_server/sambashare      /linux_mnt cifs username=ashok,password=XXXX  0 0

Sudo access to a specific command set

Lets say we have a requirement to give sudo access only to a particular command set.  Let’s take couple of scenarios like this:

1.   We want to give privilege to DBA team to mount/umount ONLY a particular filesystem ( /oracle_data) but  we don’t want them to mount/umount other filesystem.
2.   We want to give privilege to NOC team to start/stop ONLY the httpd service but we don’t want them to start/stop other services.

The syntax in /etc/sudoers file should be as follows:

%dbateam          ALL=(ALL) NOPASSWD:  /bin/mount /oracle_data, /bin/umount /oracle_data

%nocteam          ALL=(ALL) NOPASSWD:  /sbin/service httpd start, /sbin/service httpd stop, /sbin/service httpd status


Having set like this, the respective team members can execute the commands as follows:

# sudo /bin/mount /oracle_data      # Works
# sudo /bin/umount /oracle_data    # Works

# sudo /bin/mount /other_filesystem     # This will fail


# sudo /sbin/service httpd start       #  Works
# sudo /sbin/service httpd stop       #  Works
# sudo /sbin/service httpd restart   #   Fails. Since restart is not specified

# sudo /sbin/service nfs start           #  This will fail

Wednesday, December 22, 2010

Finding total size of files owned by a particular user

Syntax:

# find <pathname> -user <username> -ls | awk '{sum += $7} END {printf "Total size: %8.4f MB\n", sum/1024/1024}'

Example:
Foldername to search: /nasllm-ih
Username:  rram

[root@hostxyz ~]# find /nasllm-ih -user rram -ls | awk '{sum += $7} END {printf "Total size: %8.4f MB\n", sum/1024/1024}'                   
Total size: 958.7282 MB
[root@hostxyz ~]#


Validation:

Here I have created a folder /root/ashok consists files owned by user “adevaraju” of total size: 160 MB under its various sub-directories.

[root@hostxyz ~]# ls -lRh /root/ashok
/root/ashok:
total 21M
drwxr-xr-x 3 adevaraju root 4.0K Dec 14 06:30 d1
drwxr-xr-x 2 adevaraju root 4.0K Dec 14 06:35 d2
-rw-r--r-- 1 adevaraju root  10M Dec 14 06:21 file1
-rw-r--r-- 1 adevaraju root  10M Dec 14 06:22 file4

/root/ashok/d1:
total 21M
drwxr-xr-x 2 adevaraju root 4.0K Dec 14 06:35 dx
-rw-r--r-- 1 adevaraju root  10M Dec 14 06:22 file2
-rw-r--r-- 1 adevaraju root  10M Dec 14 06:22 file3

/root/ashok/d1/dx:
total 21M
-rw-r--r-- 1 adevaraju root 10M Dec 14 06:30 file5
-rw-r--r-- 1 adevaraju root 10M Dec 14 06:30 file6

/root/ashok/d2:
total 101M
-rw-r--r-- 1 adevaraju root 100M Dec 14 06:30 file7
[root@oralsb11-new ~]#
 [root@oralsb11-new ~]# du -sh ashok/
161M    ashok/

[root@hostxyz ~]# find /root/ashok -user adevaraju -ls | awk '{sum += $7} END {printf "SUM: %8.4f MB\n", sum/1024/1024}'
SUM: 160.0156 MB
[root@hostxyz ~]#


PS: By replacing the search folder to '/', we can find the total size of files owned by a specified user in the entire system.