0

bash script to identify the files based on current date and file name pattern .

There are 10 files located in different directory which contains date pattern in it . I need to pick these files one by one and send to remote site .

I thought to list the file naming pattern, location in config file and pick from the script but without any luck . Someone help

sample file name patter and location .

/documents/accounts/abc_yyyy-mm-dd.txt

/documents/namelist/def_yyyy-mm-dd-txt

/documents/newcustomer/ghijkl_yyyy-mm-dd-txt

date=`date +%Y-%m-%d`;
config_file="/scripts/config/abc.cfg";
echo $config_file;
URL="http://localhost:9200/document-$date";

while read var value
do
    "$var"= curl -XPUT 'http://localhost:9200/documents-'$date'/document/ 
done < /path/to/abc.config

to pick these files daily and send it to remote site using curl everyday once all the files are available .

  • 2
    Could you please edit your question to show some examples of inputs and the desired outcome, along with what you've tried and what about it didn't work the way you wanted it to? – Eric Renouf Dec 27 '16 at 13:56
1

I created this files

[leonardo4it@box4it tst] $ ll -R /home/leonardo4it/tst/*
/home/leonardo4it/tst/abc:
total 0
-rw-rw-r-- 1 leonardo4it leonardo4it 0 Dec 28 14:04 abc_2016-12-28.txt
-rw-rw-r-- 1 leonardo4it leonardo4it 0 Dec 28 14:34 excluded.txt

/home/leonardo4it/tst/shhh:
total 0
-rw-rw-r-- 1 leonardo4it leonardo4it 0 Dec 28 14:06 hbcinema_2016-12-28.txt

/home/leonardo4it/tst/u111:
total 0
-rw-rw-r-- 1 leonardo4it leonardo4it 0 Dec 28 14:06 uu_2016-12-28.txt

once built the date of the day use find like above. I get this list

[leonardo4it@box4it tst] $ export dat_day=(`date +%Y-%m-%d`)
[leonardo4it@box4it tst] $ echo $dat_day
2016-12-28
[leonardo4it@box4it tst] $ find /home/leonardo4it/tst/ -type f -name "*$dat_day.txt"
/home/leonardo4it/tst/abc/abc_2016-12-28.txt
/home/leonardo4it/tst/shhh/hbcinema_2016-12-28.txt
/home/leonardo4it/tst/u111/uu_2016-12-28.txt
| improve this answer | |
1
#!/bin/bash
date=$(date +%Y-%m-%d)
find /documents/ -type f -name "*${date}.txt" | while read filename
do
       echo "filename : ${filename}"
       #  put your transfer logic here...
done
| improve this answer | |
  • It did not work . – Codebeginner Dec 28 '16 at 10:08
  • It did not work . no results from find command , if i use simply *.txt then it gives everything from the documents folder – Codebeginner Dec 28 '16 at 10:10
  • #!/bin/bash date=date +%Y-%m-%d; config_file="/scripts/config/abc.cfg"; echo $config_file; URL="http://localhost:9200/document-$date"; find /documents -type f -name "*_'${date}'*.csv" | while read filename do echo "filename : ${filename}" var=$(base64 $filename| perl -pe 's/\n//g'); var1= curl -XPUT 'http://localhost:9200/documents-'$date'/document/?pipeline=attachment&pretty' -d' { "data" : "'$var'" }') done; – Codebeginner Dec 28 '16 at 10:32
  • why you includ single quote here.. '${date}' – Kamaraj Dec 30 '16 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.