Urgent !!! monitoring directory size using bash
Hi ppl,
I'm trying to monitor a directory, and whenever its size changes want to do some stuff... This is actually being done to patch a problem when i redeploy a struts application on sun one appserver. This is the code that does it .. #Calculate the size of application's directory initially echo -n "Creating usage stamps..." dusage=0 newdusage=0 #Test if a dir called MY_APP* exists if [ -d $_APP_SRV_DEPL_HOME/MY_APP* ] then dirName=$`ls $_APP_SRV_DEPL_HOME/ | cut -f1` echo "Name is" $dirName dusage=`du -s $_APP_SRV_DEPL_HOME/$dirName | cut -f1` newdusage=`du -s $_APP_SRV_DEPL_HOME/$dirName | cut -f1` fi echo "done" #Monitor change in directory size.. while [ $newdusage -eq $dusage ] do if [ -d $_APP_SRV_DEPL_HOME/$dirName ]; then newdusage=`du -s $_APP_SRV_DEPL_HOME/$dirName | cut -f1` #echo $newdusage sleep 1 fi done #loop ends but i get a error like ............. ........... Creating usage stamps...done ./common_libs.sh: [: -eq: unary operator expected ............................... Can u tell me whats wrong and is there any better way to do this ?? plzz I'm not a shell programmer.. so am in bit of trouble :0 |
Hi Juby,
The error pointed by you probably is on the line Code:
while [ $newdusage -eq $dusage ] Code:
dirName=$`ls $_APP_SRV_DEPL_HOME/ | cut -f1` I'm tweaking with your commands a little. It appears that it may work only if you have just one file in this directory. If one more is left in this directory you will have a mess on standard error and will measure just the size of the first file. That dollar sign will be pre-pended in the first file name, resulting in nothing to be checked by test, which is the reason of the error. If you for sure wants to evaluate the size of the directory, you just needs to run "du -s" against the directory, forgetting the files. This code would be like Code:
dusage=`du -s $_APP_SRV_DEPL_HOME | cut -f1` |
Hi,
Thanx a lot, I corrected the '$' and followed your suggestion , but now i get an error like Creating usage stamps..../common_libs.sh: [: -eq: unary operator expected the actual code is posted below.. #Calculate the size of application's directory initially echo -n "Creating usage stamps..." #Test if a dir called DOE_TCIS_200* exists if [ -d $_APP_SRV_DEPL_HOME/DOE_TCIS_200* ] then dusage=`du -s $_APP_SRV_DEPL_HOME | cut -f1` newdusage=`du -s $_APP_SRV_DEPL_HOME | cut -f1` fi while [ $newdusage -eq $dusage ] do if [ -d $_APP_SRV_DEPL_HOME ]; then newdusage=`du -s $_APP_SRV_DEPL_HOME | cut -f1` sleep 1 fi done #loop ends |
Try debug your script. To do it, enter
Code:
sh -x common_libs.sh .... |
thanx
Hi
thanx a lot man i used the debugging system and solved it.... thanx a lot once again. Btw it was the problem with the wildcard expansion, the wildcard expansion gave two directories.. that was the problem :) |
All times are GMT -5. The time now is 09:32 AM. |