LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-16-2016, 02:05 PM   #1
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Rep: Reputation: Disabled
Making directory and moving files into it using Expect


I tried several times using Expect to make a directory so I can move files into it but it keeps giving an error. Here is my code:

send "mkdir /export/home/eric/audits/\r"

This is the error I get: send: spawn id exp4 not open
while executing

I know Expect is not secure but this is the option I chose. When I try to create a folder in a bash script(using Oracle EDQ) it doesn't work either. My code in the script is:

mkdir /export/home/eric/audits/

I'm lost. PREFER to do this using Expect
 
Old 12-16-2016, 02:07 PM   #2
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
Correction using Expect:

send "mkdir //export/home/eric/reports/\r"

Last edited by trickydba; 12-16-2016 at 02:09 PM.
 
Old 12-16-2016, 05:47 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,613

Rep: Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169
FYI although it does not affect anything you do not need to use a a double forward slash (//) in your commands.
 
1 members found this post helpful.
Old 12-23-2016, 02:47 PM   #4
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
When I try this Im getting an error, even in command line:

scp "${current_folder}" eric@hostname:/export/home/eric

I get this error after giving my password:

20161223: not a regular file

Im actually trying to copy/move a whole folder to a different location(from linux to win shared folder)
 
Old 12-23-2016, 03:01 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,613

Rep: Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169
You need to use the -r (recursive option). See scp man pages for more info...
 
1 members found this post helpful.
Old 12-23-2016, 03:11 PM   #6
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
The 'current_folder' variable is set up as such:

current_folder="$(date +%m%d%Y)"

I'm trying to make the folder created look like this - 12232016
But it's still coming up like this - 20161223

What am I doing wrong?
 
Old 12-23-2016, 03:17 PM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,613

Rep: Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169
We can not tell without seeing your script. As suggested in a previous thread its actually easier to search/list using Ymd then mdy format
 
Old 12-23-2016, 03:22 PM   #8
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
I provided the script to the date variable above. The full script is:

scp "${current_folder}" eric@hostname:/export/home/eric

current_folder="$(date +%m%d%Y)"

When this script is ran,, it is already in the folder where the current dated folder exists
 
Old 12-23-2016, 03:28 PM   #9
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
Stoopid me, I was changing the wrong script. I code above works.
 
Old 12-23-2016, 03:44 PM   #10
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
I tried this code with no results:

current_folder="$(date +%m%d%Y)"

scp -r "${current_folder}" eric@hostname:/export/home/eric
 
Old 12-23-2016, 03:48 PM   #11
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,613

Rep: Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169
How is the script run with respect to the path environment and the location of current_folder?
 
Old 12-23-2016, 03:51 PM   #12
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
The script would be ran using Expect. The folder the script is running in is export/home/eric/reports/. Which is where the folder 12232016 resides.
The location of the destination folder is in Windows (export/home/eric/reports/destinationfolder/

I hope this answers your question
 
Old 12-23-2016, 03:53 PM   #13
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
Does the command 'sftp' recognize variables?
 
Old 12-23-2016, 03:55 PM   #14
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
Believe me I tried the easiest way(keys) but that is waaaay too confusing and this whole process is working WITH keys in a PowerShell script. I love Linux which is better and figured I could this this without having to go through setting up keys cause it's already been done in Windows
 
Old 12-23-2016, 04:02 PM   #15
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
Im having to move this folder manually using FileZilla. I wonder if 'sftp' should be the way to go? If so, it would have to recognize variables
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Moving files between Folders in Remote directory Saratha Linux - Newbie 5 03-29-2013 02:37 PM
Moving files from one directory to another based on 2 date variables dsfreddie Linux - Newbie 4 06-28-2012 11:14 AM
[SOLVED] Help making specific script loop over multiple files in directory novloski Linux - Newbie 3 05-11-2011 05:13 AM
Processing multiple files in a directory and moving them. keysorsoze Linux - Newbie 14 12-26-2007 05:27 AM

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

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