Home > Mobile >  du: cannot access '/tmp/swapnil-httpd-log-04072022-125152.tar
du: cannot access '/tmp/swapnil-httpd-log-04072022-125152.tar

Time:07-05

Hello Everyone,

I am getting below error in one of my script

du: cannot access '/tmp/swapnil-httpd-log-04072022-125152.tar

#this i have use in script which get me a size of tar file tar_size=$(du -h /tmp/${name}-httpd-log-${timestamp}.tar | awk '{print $1}')

this is output of long list command on tmp

-rw-r--r-- 1 root root 10240 Jul 4 12:51 swapnil-httpd-logs-04072022-125152.tar

what i am doing wrong

CodePudding user response:

Could it be that the value of either name or timestamp changes between when you create the file and when you check its size?

In these situations, you're probably better off creating a separate variable filename that you set only once, and then use each time you refer to the file.

Also, maybe consider using ls -l to get the file size?

CodePudding user response:

There is maybe a typo error. Fixed:

tar_size=$(du -h /tmp/${name}-httpd-log[s]-${timestamp}.tar | awk '{print $1}')

Or

tar_size=$(du -h /tmp/${name}-httpd-logs-${timestamp}.tar | awk '{print $1}')

  • Related