0

I have built an ftp server on google compute engine that receives data from on prem systems as csv. I want to move this data after receiving it to a google cloud storage using a cron job from the vm ssh. in addition to that I want to add the timestamp to the file name when moving it to the storage bucket.

what I have tried as a cron job is

*/2 * * * * gsutil mv *.txt gs://univer-bucket/$(date).txt

but the job did not work and I don't know how to keep the old name and just add to it the timestamp

thanks in advance :)

1 Answer 1

1

This mv command says something like "move all files with .txt extension to the gs://univer-bucket/$(date).txt". This would work only if the gs://univer-bucket/$(date).txt is folder, which I assume isn't.

You need to run mv for each individual file using for loop. Also I would recommend you to specify format of the date for the date command.

Resulting line in the crontab could be:

*/2 * * * * for file in *.txt; do gsutil mv "$file" "gs://univer-bucket/$(date +%Y-%M-%d-%H%M)-$file.txt"; done
1
  • Thanks for the help :) :)
    – Be2
    Commented Sep 2, 2019 at 14:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .