1835953 Members
2427 Online
110088 Solutions
New Discussion

Re: Perl script help

 
SOLVED
Go to solution
Kris_5
Occasional Advisor

Perl script help

Dear all,

I am new to the perl and am trying to write a small script which calculates the disk usage by a directory. I tried to use the following command to get the size in KB in perl script.

$oraclin_data_sz=`du -sk $oraclin_data/$db_study_name|awk -F" " '{print $1}'` ;

Some how the above script return both size as well as the dir name. Could somebody help on how to strip the dir from the about command output. TIA

3 /opt/ORACLE/odc/dev/aps

Kris
3 REPLIES 3
steven Burgess_2
Honored Contributor
Solution

Re: Perl script help

Hi Kris

drop the field seperator -F" " and just use

$oraclin_data_sz=`du -sk $oraclin_data/$db_study_name | awk '{print $1}'

HTH

Steve
take your time and think things through
Jordan Bean
Honored Contributor

Re: Perl script help

You don't even need awk.

$oraclin_data_sz = [split /\s+/, `du -ksx $oraclin_data/$db_study_name`]->[0];

Caesar_3
Esteemed Contributor

Re: Perl script help

Hello!

Remove the option of field separetor in awk.
If that's all that your script do i don't think that you need to use perl for this.
You use to much of unix commands to do this.
All the separate the fields you can use split
from perl functions.

Caesar