LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-18-2016, 12:28 AM   #1
rsi142
LQ Newbie
 
Registered: Oct 2016
Posts: 9

Rep: Reputation: Disabled
How to get time and use rsync in same script


Actually i need to copy the file from remote server using rsync and also need to get the date because the name of the file is access.2016-11-16.log
and i need to get the file in daily basis so the next day the name of the file will be access.2016-11-17.log
my code
#!/usr/bin/expect

#w="$(date)"
#printf "Current date and time %s\n" "$now"

now="$(date +'%Y-%m-%d')"
#printf "Current date in dd/mm/yyyy format %s\n" "$now"
x="access."$now
echo $x

spawn rsync --inplace --no-whole-file root@10.207.5.1:/app/hybris/hybris/l...2016-11-16.log .

#spawn rsync -v root@10.207.16.45:/u02/opt/weblogic/...ogs/access.log .
expect "*root@10.207.5.199's password:" {
send "******"
expect "\r"
expect "*\r"
}

spawn rsync --inplace --no-whole-file root@10.207.5.199:/app/hybris/hybris...e-20161116.log .

#spawn rsync -v root@10.207.16.3:/u02/opt/weblogic/d...ogs/access.log .
expect "*root@10.207.5.199's password:" {
send "******\r"
expect "\r"
expect "*\r"
}
 
Old 11-18-2016, 12:54 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
please use [code][/code] tags around your code to keep formatting.
I do not really understand, you have only one access.log and want to copy day by day using different names, or do you have new file(s) every day?
 
Old 11-18-2016, 01:04 AM   #3
rsi142
LQ Newbie
 
Registered: Oct 2016
Posts: 9

Original Poster
Rep: Reputation: Disabled
actually everyday new logs are created and name is also new
name would be like
acces.presentdate.log
 
Old 11-18-2016, 01:10 AM   #4
rsi142
LQ Newbie
 
Registered: Oct 2016
Posts: 9

Original Poster
Rep: Reputation: Disabled
Answer to the question

#!/bin/sh

#w="$(date)"
#printf "Current date and time %s\n" "$now"

now="$(date +'%Y-%m-%d')"
#printf "Current date in dd/mm/yyyy format %s\n" "$now"
x="access."$now
y=x."log"
echo $y
expect <<EOS

#!/usr/bin/expect
spawn rsync --inplace --no-whole-file root@10.207.5.199:/app/hybris/hybris/log/tomcat/$x.log .

#spawn rsync -v root@10.207.16.45:/u02/opt/weblogic/...ogs/access.log .
expect "*root@10.207.5.199's password:" {
send "password\r"
expect "\r"
expect "*\r"
}

spawn rsync --inplace --no-whole-file root@10.207.5.192323:/app/hybris/hyb...e-20161116.log .

#spawn rsync -v root@10.207.16.45:/u02/opt/weblogic/...ogs/access.log .
expect "*root@10.207.5.2323's password:" {
send "password\r"
expect "\r"
expect "*\r"
}
EOS
 
Old 11-18-2016, 01:44 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
if you could set ssh keys:
Code:
filename="$(date +'access.%Y-%m-%d.log')"
rsync --inplace --no-whole-file root@10.207.5.199:/app/hybris/hybris/log/tomcat/$filename .
will be enough (or something similar), no need to use expect
but anyway rsync is able to copy only new files, so probably you only need to rsync directory and new file(s) will be automatically found and transferred (no need to construct the name of it).
 
  


Reply

Tags
date, rsync, sh



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] rsync updating time Jeff9 Linux - Newbie 10 04-26-2014 01:49 PM
rsync without copying files when the only difference is the time time centguy Linux - Mobile 2 12-01-2012 08:15 PM
Each time a script is called. A log file is created with time and date + Bash Script. y0_gesh Programming 6 08-17-2012 03:16 AM
Need help to have a rsync script log output to a file with time stamp Thaidog Programming 5 11-15-2011 05:37 PM
Rsync For The 1st Time carlosinfl Linux - General 1 08-29-2007 11:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration