LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-05-2017, 06:55 AM   #1
Preeti mohanty
LQ Newbie
 
Registered: Mar 2017
Posts: 3

Rep: Reputation: Disabled
Question shell script to copy from production to DR


Hi

if any changes would work

Last edited by Preeti mohanty; 03-07-2017 at 06:06 PM. Reason: nothing
 
Old 03-05-2017, 03:54 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,658

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
Quote:
Originally Posted by Preeti mohanty View Post
Hi
I want a shell script that copies user generated reports from production to DR. AND also report generated in DR move the scripts from DR location to prod location. I tried my own way it's not working.
Code:
*#!/bin/sh

file1=user1@domain2.com:/path1/file1.txt (completePath to file1.txt)*
file2=user1@domain2.com:/path2/file2.txt (completePath to file2.txt)*

files=( ${file1} ${file2} )

scp ${files[@]} /home/path3*
Please use CODE tags when posting code. And is this the EXACT SCRIPT you're using?? Because there are several issues with it...can you tell us what it's not doing? Because just saying "it's not working", gives us nothing to go on.

To start:
  • Your script should start with #!/bin/bash for a bash script, but /bin/sh may work fine too....but the * in front of it????
  • Your file variables contain special characters (The @, :, and /), and there is no comment after the "file1.txt"...so the entire (completePath to file1.txt)* is being put INTO that variable too
  • The "files" array (ASSUMING you want an array here?) isn't defined correctly. Syntax is "array=( [XX]=<value> [XX]=<value> . . . )"
  • You aren't looping through the array to actually perform the SCP.
  • The "/home/path3*" isn't going to work. Needs to have a trailing "/home/path3/*" (bad), or "/home/path3" (correct)
This:
http://www.tecmint.com/working-with-...ell-scripting/

...has an example script containing an array and correct syntax. You should be able to modify it to suit.
 
1 members found this post helpful.
Old 03-05-2017, 05:16 PM   #3
iPad
Member
 
Registered: Oct 2016
Distribution: iPadLinux
Posts: 81
Blog Entries: 1

Rep: Reputation: 45
Post exactly what it says when you try it!

What you posted is just a copy of this:
http://www.unix.com/302661795-post5.html
 
Old 03-05-2017, 05:35 PM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by Preeti mohanty View Post
Hi
I want a shell script that copies user generated reports from production to DR.
AND also report generated in DR move the scripts from DR location to prod location.
Sounds like a job for rsync.
 
Old 03-06-2017, 10:46 AM   #5
Preeti mohanty
LQ Newbie
 
Registered: Mar 2017
Posts: 3

Original Poster
Rep: Reputation: Disabled
i tried this ... to transfer of generated reports from from prod to dr server. anyone can sort it


#!/bin/sh
ftpuser="userid"
ftppass="passord"
ftpdest="destination server name"
ftpdate="date+%d"

outdir="home server path"
ftppath="destination server path"
log_dir="log directory path"

cd $out_dir

for ftpfile in 'ls'
do
echo"open ${ftpdest}
user ${ftpuser} ${ftppas}
asci
put ${ftpfile}
bye " | ftp -i -n -v >> ${log_dir}/log_${filedate}
done
 
Old 03-06-2017, 10:57 AM   #6
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
Quote:
Originally Posted by Preeti mohanty View Post
anyone can sort it
Welcome.

You'll need to back up a few steps. FTP should never, ever be used any more for transfer over the Internet. With FTP all your login credentials (username and password) as well as the data are transmitted unencrypted. Your machines will get compromised using that method. If you invest now in learning the right way, you will save a lot of effort by avoiding cleanup later. Not only that, the correct methods for file transfer will be less effort to implement.

As already suggested, rsync is a good option as it connects over SSH. Alternately, you can use plain SFTP, that also connects over SSH and has a batch mode which is useful for automation. SFTP fits into scripts in a way somewhat similar to FTP, but with the difference that it can actually be secure.

Either way, SFTP or rsync, your second step will be to set up key-based authentication over SSH so that can be the basis of your transfer. The first step, and top priority, should be decommissioning the FTP daemon.
 
Old 03-06-2017, 11:32 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,658

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
Quote:
Originally Posted by Preeti mohanty View Post
i tried this ... to transfer of generated reports from from prod to dr server. anyone can sort it
Code:
#!/bin/sh
ftpuser="userid"
ftppass="passord"
ftpdest="destination server name"
ftpdate="date+%d"

outdir="home server path"
ftppath="destination server path"
log_dir="log directory path"

cd $out_dir

for ftpfile in 'ls'
do
echo"open ${ftpdest}
user ${ftpuser} ${ftppas}
asci
put ${ftpfile}
bye " | ftp -i -n -v >> ${log_dir}/log_${filedate}
done
Again, as you were asked before, put your code in CODE tags. Also, asking "anyone can sort it" is fairly rude, considering you never answered the first questions about your initial script. You're essentially asking us to write your script for you, and not even telling us what problem(s) you're having, message(s)/error(s) you're seeing, or even what version/distro of Linux you're using. And you've even gone back and edited your original question and changed what it said.

Again, its been suggested that you use rsync; you were given a link to a page with a sample script on it, which could have been easily modified to do what you're after. And you've only posted a second script that you copied from somewhere, without giving us any details. If you don't provide details, tell us what you're seeing/where, or even answer questions when asked, there is ABSOLUTELY NOTHING we can do to help you.
 
Old 03-06-2017, 05:05 PM   #8
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,993

Rep: Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628
I use autoexpect to make these sorts of scripts.
 
Old 03-07-2017, 05:50 PM   #9
Preeti mohanty
LQ Newbie
 
Registered: Mar 2017
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
Again, as you were asked before, put your code in CODE tags. Also, asking "anyone can sort it" is fairly rude, considering you never answered the first questions about your initial script. You're essentially asking us to write your script for you, and not even telling us what problem(s) you're having, message(s)/error(s) you're seeing, or even what version/distro of Linux you're using. And you've even gone back and edited your original question and changed what it said.

Again, its been suggested that you use rsync; you were given a link to a page with a sample script on it, which could have been easily modified to do what you're after. And you've only posted a second script that you copied from somewhere, without giving us any details. If you don't provide details, tell us what you're seeing/where, or even answer questions when asked, there is ABSOLUTELY NOTHING we can do to help you.
Hi

it shows ksh: syntax error: 'for' unmatched

i was not rude to ask you such question. my script was not copied from some where else and it was done my me. if you wish to reply then its good or else no need it seems.
 
Old 03-07-2017, 06:28 PM   #10
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,658

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
Quote:
Originally Posted by Preeti mohanty View Post
Hi
it shows ksh: syntax error: 'for' unmatched

i was not rude to ask you such question.
You were not rude for asking a question, but when you:
  • You ignored questions when asked
  • You provided no details when asked
  • You ignored the CODE tags when asked (twice)
  • You edited your first post, removing the script and changing it, making it hard for anyone to keep track of what you're asking about
And now you post "if you wish to reply then its good or else no need it seems.", after I tried to help and answer your questions, line by line, in my first reply, and following that up with "anyone can sort it". Those things are a bit rude, yes.

Quote:
Originally Posted by Preeti mohanty
my script was not copied from some where else and it was done my me.
Your first script was posted here:

http://www.unix.com/302661795-post5.html

..five years ago. The only detail you've now provided is that you're getting an unmatched "for"....which script is this in, the one you FIRST posted, or the one you edited/posted again? Guessing the second, and if it stands as you posted it, you have two unmatched double-quotes on different lines, and (since no CODE tags were used), the spacing/indention is impossible to see.

Again...rsync does what you're after, better and more securely. SFTP would be a FAR better way to go, and easier to script for, since it is not only encrypted, but can be passwordless via key exchanged. But you still haven't shared any details, told us your goals, etc. We are happy to try to help you, but ignoring what everyone says, not answering questions, and editing posts (repeatedly in this case, re: post #1), makes it impossible for anyone to help you.

Last edited by TB0ne; 03-07-2017 at 06:44 PM.
 
Old 03-07-2017, 06:28 PM   #11
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,663

Rep: Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710
Quote:
Originally Posted by Preeti mohanty View Post
Hi

it shows ksh: syntax error: 'for' unmatched

i was not rude to ask you such question. my script was not copied from some where else and it was done my me. if you wish to reply then its good or else no need it seems.
I do not think we can get upset with this user: he has no idea how to ask the questions properly or provide the information we would need to provide an answer that would help him.

Pointing him to the articles about the tags and how to ask an intelligent question MIGHT help.

Preeti: I recommend:
1. that you research the tools here for posting better questions.
2. that you consider the advice given that 'expect' tools may not be the correct tools for what you want to accomplish. One recommendation was rsync in a bash script, but other tools could also be used.
3. that after some time to research and consider, you come back here and post an update with information clearly posted that might help us to help you.
 
2 members found this post helpful.
  


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
Shell script to copy the logs from production to DR abhilashsriram Linux - Newbie 2 10-25-2013 10:10 AM
[SOLVED] script as shell for non-production user in /etc/passwd drManhattan Linux - Server 4 12-28-2011 06:08 AM
shell script to copy files eduard Linux - Newbie 9 07-13-2011 03:26 PM
Shell Script to copy and number files extasic Programming 1 12-12-2008 06:29 AM
shell script to copy lines from a file Warmduvet Programming 2 09-14-2004 09:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

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