LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 12-15-2016, 01:26 PM   #1
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Rep: Reputation: Disabled
Move files with appended date using SCP


Let's say I have these files in a folder:

File1_2016_12_15.xlsx
File2_2016_12_15.xlsx

and I want to move them to a different location (using a wildcard of course) using SCP, how can this be done?
 
Old 12-15-2016, 01:33 PM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
How far does this get you?

https://www.linuxquestions.org/quest...ml#post5642523
 
1 members found this post helpful.
Old 12-15-2016, 01:53 PM   #3
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
I can do that for one file, but I have several files that are in this format:

name_name_20161215.xlsx

I tried scp *$(date -d today +"_%Y%m%d'xlsx") username@hostname://dir1/home/eric/reports/AUDITS

with no success
 
Old 12-15-2016, 01:56 PM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Try with a dot.

Code:
scp *_$(date -d today +"%Y%m%d").xlsx username@hostname:/dir1/home/eric/reports/AUDITS/
Also, be sure to identify the last part of the path as a directory.

Last edited by Turbocapitalist; 12-15-2016 at 01:58 PM.
 
1 members found this post helpful.
Old 12-15-2016, 01:59 PM   #5
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
I solved it! Here is my code:

scp -p filename*.xlsx filename2*.xlsx username@hostname://dir/dir2

Thank you for all the help!!!
 
Old 12-15-2016, 02:04 PM   #6
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@Turbocapitalist............your code works too!!!! Thank you!!!!!!!! Think I'll use yours, it looks cleaner and makes me look smarter! LOL
 
Old 12-15-2016, 10:17 PM   #7
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Excellent. Be sure to skim the manual pages for the parts you used. Over time you'll pick up more.

Code:
man 7 glob
man date
man scp
man ssh_config
 
Old 12-15-2016, 10:31 PM   #8
TheEzekielProject
Member
 
Registered: Dec 2016
Distribution: arch
Posts: 668

Rep: Reputation: 190Reputation: 190
Maybe I am misunderstanding exactly what you're trying to do but you should be able to accomplish this with rsync as well, e.g.

rsync /source* username@hostname:/destination/
 
1 members found this post helpful.
Old 12-16-2016, 08:17 AM   #9
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@The_EzekielProject & TurboCapitalist..............both of your solutions works, in command line BUT when I use it in a script (with Except, which is basically command line) it doesn't work. Now if the file does not have an appended date, it works beautifully in a script. I'm thinking ahead now and what would be better is to first create a folder named with the current date, then move all files with extension 'xlsx' into that folder
 
Old 12-16-2016, 08:47 AM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,743

Rep: Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923
expect is an extension of tcl which does not have wildcard expansion. You can use the glob command but it has been long time since I've used tcl/expect except for simple scripts. Your workaround might be the easiest at the moment to keep from learning another language.
 
1 members found this post helpful.
Old 12-16-2016, 09:00 AM   #11
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Try it with keys instead rather than "expect", that way you can use a regular shell (bash) script.
 
Old 12-16-2016, 09:08 AM   #12
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@Turbocapitalist....when you say keys you are talking about putting in the script something like hostkey="ssh-rsa 2048 00:44:22:11:1f:11 etc etc or are you talking about a file in a certain location that has the key in it?
 
Old 12-16-2016, 09:24 AM   #13
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
You'd make a key using ssh-keygen and then copy it to the server with ssh-copy-id (or a manual transfer). Then you can log in with the key and do not need expect any more.

Code:
cd ~/.ssh/
ssh-keygen -f hostname_ed25519 -t ed25519 -C "username's script"
ssh-copy-id -i hostname_ed25519 user@hostname
That generates a key and copies it to the remote host. Then you can connect by pointing ssh or scp to it.

Code:
ssh-add ~/.ssh/hostname_ed25519
scp -i ~/.ssh/hostname_ed25519 \
    *_$(date -d today +"%Y%m%d").xlsx \
    username@hostname:/dir1/home/eric/reports/AUDITS/
That's the gist, but there are a lot of tutorials on the topic. Do use a strong passphrase for the key.
 
Old 12-16-2016, 09:27 AM   #14
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
https://linuxconfig.org/passwordless-ssh
 
Old 12-16-2016, 09:29 AM   #15
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@Turbocapitalist.......what is the 'ed25519' for?
 
  


Reply



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
Delete/move/copy files of specific date imsajjadali Red Hat 26 11-07-2013 11:34 PM
Bash script help - Capture output of ls - move files according to date wayneywoo Programming 5 04-23-2013 08:45 AM
move files based on date graphicsmanx1 Programming 7 12-18-2012 01:49 AM
[SOLVED] Bash script to move files from date cbing Programming 9 04-20-2012 05:45 AM
"How to rename files with current date stamp appended into name using shell script?" nandi Linux - Newbie 4 10-05-2011 10:36 AM

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

All times are GMT -5. The time now is 03:36 PM.

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