date format linux

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

date format linux

Roshan
CentOS Linux release 7.8

Hello Erman,

I have created a bash script to copy files from 1 directory /archive to another directory voicenew. After copy, I will unzip the files.

The issue is if I store the current date in a variable (yesterday), the variable will store sysdate+1. For e.g, if today is 24, I will get error below

cp: cannot stat ‘/cdr/RECHARGE/recharge/archive/recharge/archive/*20210325*’: No such file or directory

Script:

cd /cdr/VOICE/VOICE/voice/voicenew/
find . -name "*.add" -print0 | xargs -0 rm
find . -name "*.gz" -print0 | xargs -0 rm

yesterday=$(date -d "$date  days" +"%Y%m%d")
cp /cdr/VOICE/VOICE/voice/archive/voice/archive/*$yesterday* /cdr/VOICE/VOICE/voice/voicenew/
y| find  /cdr/VOICE/VOICE/voice/voicenew/ -type f -exec gunzip {} +

Kindly advise.

Thanks,

Roshan
Reply | Threaded
Open this post in threaded view
|

Re: date format linux

ErmanArslansOracleBlog
Administrator
If I correctly understand you, you want that yesterday to be set to the value of 'today', the current date I mean. Why do you name that variable as "yesterday" is another question? :) why do you "days" argument there? I didn't see any reason to use it. Why do you use an empty $days variable in front of that days argument is another question..
Anyways;  Why dont you just use -> date +"%Y%m%d" ?
Reply | Threaded
Open this post in threaded view
|

Re: date format linux

ErmanArslansOracleBlog
Administrator
If you want or insist on using that "date -d" , then you can also make it work with the following;

date -d "`date` 0 days" +"%Y%m%d"

But it is unnecesary to use it that way in this case..
Reply | Threaded
Open this post in threaded view
|

Re: date format linux

Roshan
In reply to this post by ErmanArslansOracleBlog
Thanks it is ok after I removed days.. I will change the variable yesterday. I was using for testing.