LinuxQuestions.org
Help answer threads with 0 replies.
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-14-2016, 06:46 AM   #1
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Rep: Reputation: Disabled
Copy files into current dated folder


I had a major previous issue moving files from Linux to a Windows shared folder. This is the code that resolved my issue, using Expect:

#!/bin/bash
expect -c "
spawn scp -p file.xlsx exg85@hostname://export/home/exg85/reports/destinationoffile
expect "assword"
send "mypswd\r"
expect "reports]$"
spawn scp -p file2.xlsx exg85@hostname://export/home/exg85/reports/destinationoffile
expect "assword"
send "mypswd\r"
expect "reports]$"
send "exit\r"
interact "

Now, I would like to autogenerate a folder that would be named the current date and move the file into this folder on a daily basis.
 
Old 12-14-2016, 07:33 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
I would avoid use of "expect" and use keys instead. The former is clunky and unsafe.

Code:
date=$(date +"%F");
ssh -i /home/trickydba/.ssh/your_key_ed25519 exg85@hostname mkdir -p /export/home/exg85/reports/$date/
scp -i /home/trickydba/.ssh/your_key_ed25519 \
    /path/to/source/file*.xlst \
    exg85@hostname:/export/home/exg85/reports/$date/
 
1 members found this post helpful.
Old 12-14-2016, 08:07 AM   #3
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
The code above has resolved my issue. Thank you Turbocapitalist!
 
  


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
find all the current log file with date and copy to a specific folder. boby.kumar Linux - Newbie 5 11-22-2015 06:52 AM
How copy older backup files into new folder witout losing new additional files thm Linux - Server 3 09-04-2015 04:32 PM
[SOLVED] Using terminal command -Find files in a folder and copy them to a different folder j-jock Linux - General 4 11-28-2011 02:20 AM
Slackware '-current' '/usr/share/pci.ids' file is dated onebuck Slackware 6 03-09-2010 12:59 PM
i need to copy files from one folder to another folder using shell anurupr Linux - Newbie 17 03-04-2010 09:07 AM

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

All times are GMT -5. The time now is 11:01 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