LinuxQuestions.org
Review your favorite Linux distribution.
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-23-2016, 04:31 PM   #16
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,613

Rep: Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169

I've tested scp both on the command line and via expect and it works so not sure where you are having problems. If your in the parent directory then the below command should work from the command line. The -r will create a subdirectory i.e. /export/home/eric/12232016 with its contents.

scp -r 12232016 eric@hostname:/export/home/eric

With expect I've used $current_folder,"$current_folder" and "${current_folder}" in my test script and it works as well. So it could be your script.

Were there any error messages?
 
1 members found this post helpful.
Old 12-25-2016, 07:59 PM   #17
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
Well I have the creating of the directories solved, adn all the files are moved into that folder. It's just that I'm trying to move this folder into the windows shared folder.
 
Old 12-25-2016, 08:02 PM   #18
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
Can you send me a sample of your test script where you are simply moving files into a windows shared folder using Expect with the folder being moved named in the variable "$current_folder"?
 
Old 12-25-2016, 08:24 PM   #19
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
I tried this:

scp -r "$current_folder" username@hostname:"/dir1/main dir/writehere/"

Only to get this:

scp: ambiguous target


and yes, I put the space in one of the directories on purpose cause it is a similar situation
 
Old 12-26-2016, 08:57 AM   #20
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,613

Rep: Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169Reputation: 4169
I am probably leading you astray since I do not have a ssh server installed on a windows computer. I am using another linux computer. However the "scp: ambiguous target" is due to the spaces in the destination path. You need to add backslashes to escape the spaces. In a script you need to add two backslashes but I have not tried to see if it also works in expect.

cp -r "$current_folder" username@hostname:"/dir1/main\ dir/writehere/"


Here is my test code. I am passing the source directory as a command line argument.

Code:
#!/usr/bin/expect -f
set timeout 9
set directory [lindex $argv 0]
if {[llength $argv] == 0} {
  send_user "Usage: upload directory\n"
  exit 1
}
spawn scp -r "$directory" user@host:/upload_directory
expect {
  timeout { send_user "\nFailed to get password prompt\n"; exit 1 }
  eof { send_user "\nSSH failure for server\n"; exit 1 }
  "*assword"
}
send "password\r"
expect {
  timeout { send_user "\nLogin failed. Password incorrect.\n"; exit 1}
  "*\$ "
}
send_user "\nPassword is correct\n"
 
1 members found this post helpful.
Old 01-03-2017, 07:07 AM   #21
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
Thank you for all the help. I have abandoned the use of Expect and have had the issue resolved. The actual problem was the permissions. I used the code mentioned above by michaelk:

scp -r 12232016 eric@hostname:/export/home/eric

A combination of using the suggested code AND resolving the issue with permissions has totally resolved my issue.
 
  


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: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