I am stuck with commands in Linux where logic is below. Getting the list of files with Yesterday and they-before-yesterday with creation date and renamining them and transfer via scp.
file name should be like <<<YYYYMMDD_creation_date_of_that_filename>>>_filename.
for e.g.
- getting output
ls -lrth --time-style=+"%Y%m%d" | egrep "
date -d ‘1 day ago’ ‘+%Y%m%d’|
date -d ‘2 day ago’ ‘+%Y%m%d’" > tmp.txt
-rw-rw-rw- 1 user user 418K 20211225 log.897.gz
-rw-rw-rw- 1 user user 419K 20211225 log.898.gz
-rw-rw-rw- 1 user user 419K 20211225 log.899.gz
-
renaming. this will rename with creation time of that same file as suffix
for f in tmp.txt|awk '{print$7}'; do cp "$f" "$(stat -c %Y "$f" | date +%Y%m%d)_$f"; done
-
transfer all these file in one go
for i in list_of_file_from_above; do scp $i [email protected]:/target/folder;done
I am stuck in somewhere loop.
also every time i have to enter password for scp
Please help.
“tar” option can also be considered.