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 01-12-2013, 09:30 AM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,197

Rep: Reputation: 45
Help me with my first bash script


Dear all
I am using a script as this one here to download files from my pc to a remote laptop

#!/bin/bash


rsync -av --rsh='ssh -p9902' aaa@156.112.211.511:/home/user/Documents/ /home/user/Documents/Paper/


I would like before the execution to inform the user that this will copy the files from the host as above to the current pc and ask for a confirmation from the user.

Is that possible?

Regards
Alex
 
Old 01-12-2013, 10:50 AM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Do you want something like this, when a user invokes the script:-
Code:
#!/bin/bash
echo -n "Do you want to copy the file [yes/no]: "; read ans
case $ans in
yes) 
rsync -av --rsh='ssh -p9902' aaa@156.112.211.511:/home/user/Documents/ /home/user/Documents/Paper/ ;;
no) echo "Exiting" ;;
*) echo "Wrong choice entered. Exiting"
exit 1;;
esac
 
Old 01-12-2013, 11:00 AM   #3
Rupadhya
Member
 
Registered: Sep 2012
Location: Hoffman Estates, IL
Distribution: Fedora 20
Posts: 167

Rep: Reputation: Disabled
You could do something like this from the command prompt..

Code:
#!/bin/bash
# This script will input data from the user

echo "About to upload some files to the server.  Is this OK? (y/n)"

read stuff

if [ "$stuff" == "y" ] ; 
   then 
     echo "Starting the Upload..."
   else
     echo "Aborting the Upload..."
fi
- Raj
 
Old 01-23-2013, 11:24 AM   #4
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,197

Original Poster
Rep: Reputation: 45
Thanks a lot. My script now works.
I would like to ask you, if possible, before rsync syncs the files to the destination make a backup (meaning tar.gz of the folder is going to change). Would that be possible and if yes how?

Alex
 
Old 01-23-2013, 11:31 AM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,561

Rep: Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127
You've been a member here for 10 years and have over 2000 posts and don't know how to make a tar ball or read the man page on tar?

Code:
tar -zcf /home/user/Documents/Paper_backup.tar.gz /home/user/Documents/Paper
 
1 members found this post helpful.
Old 01-23-2013, 04:28 PM   #6
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,452

Rep: Reputation: 85
As you had said in your double post, rsync is for syncronizing between target and destination. If it prompted you to overwrite files, the target and destination wouldn't necessarily be syncronized. however, an rsync like clone that does what you're asking can all be scripted in bash using some command line utilities like diff and md5sum to check which files differ as well as mv -i (see -i in the man page).
 
  


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
Why does this work from the bash command line and then fails in a bash script? Rupadhya Linux - Newbie 5 09-26-2012 01:05 AM
How to get some bash scripts into a simple bash script with some echo and if statement. y0_gesh Programming 3 03-01-2012 10:46 AM
[SOLVED] Run multiple bash and php scripts from a bash script charu Programming 5 07-26-2011 03:40 AM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 09:56 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 12:10 PM

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

All times are GMT -5. The time now is 03:07 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration