Sponsored Content
Full Discussion: Remote Copy Script
Top Forums Shell Programming and Scripting Remote Copy Script Post 302513295 by effektd on Tuesday 12th of April 2011 08:31:15 PM
Old 04-12-2011
Hi pludi,

Thanks for your input, I've made adjustments to the script as suggested. I'm going to learn about looping to see if I can optimise the script a bit more.

The $ behind read was from what I found on a website discussing it's purpose, I did think it was a bit strange.

I'll run the checks now, if I've made a mistake, I'd appreciate it being pointed out!

Cheers,
effektd

Code:
#!/bin/bash

# This bash script is used for the slightly automated process of exporting log files from the XXXXXXX Servers
# Version: 0.2
# Last Updated: 13/04/2011

# Date variable
BKDATE=$(date +%Y%m%d)

echo THIS BASH SCRIPT IS TO BE USED FOR THE EXPORTATION OF ALL SERVER LOGS TO A USB
echo THE FOLLOWING CONDITIONS MUST HAVE BEEN COMPLETED BEFORE RUNNING THIS SCRIPT....
echo 1. YOU MUST BE LOGGED IN ON THE ROOT ACCOUNT OF XXXXX SERVER SERVER01. THIS SCRIPT WILL NOT WORK ON THE OTHER SERVERS!
echo 2. THE USB DRIVE MUST BE INSERTED AND MOUNTED DIRECTLY TO /mnt/ WITHOUT A FOLDER NAME PRIOR TO RUNNING THIS SCRIPT
echo If the drive is not mounted please type the following; mount -t vfat /dev/sdb1 /mnt/ (kill this script before attempting to run command)
echo NOTE: sdb1 may NOT be the correct dev for the USB refer to notes if an error occurs

read -p "If the above has been completed press ENTER to continue....if it hasn't please exit the script"

echo Now creating directories on /mnt/

# This first command will first create a current date directory on the USB Drive
mkdir /mnt/$BKDATE/

# The following commands will then create all relevant server folders within the current date of this backup process taking place
mkdir /mnt/$BKDATE/SERVER01
mkdir /mnt/$BKDATE/SERVER02
mkdir /mnt/$BKDATE/SERVER03
mkdir /mnt/$BKDATE/SERVER04
mkdir /mnt/$BKDATE/SERVER05
mkdir /mnt/$BKDATE/SERVER06
mkdir /mnt/$BKDATE/SERVER07
mkdir /mnt/$BKDATE/SERVER08
mkdir /mnt/$BKDATE/SERVERR01
mkdir /mnt/$BKDATE/SERVERR02
mkdir /mnt/$BKDATE/SERVERR03

read -p "The directories have been created on the USB, press ENTER to being the copy process..."

# This first command is only using cp as you are already on the SERVER01 box and don't need to use scp (for remote copy)
cp /var/log/* /mnt/$BKDATE/SERVER01

# The following commands will now execute Secure Remote Copy using the root account of all servers. It will prompt for the password for each instance
# We are not using an RSA Public Key and therefore cannot avoid the need to enter in the password for each server instance
scp root@xxx.xxx.xxx.xxx:/var/log/* /mnt/$BKDATE/SERVER02
scp root@xxx.xxx.xxx.xxx:/var/log/* /mnt/$BKDATE/SERVER03
scp root@xxx.xxx.xxx.xxx:/var/log/* /mnt/$BKDATE/SERVER04
scp root@xxx.xxx.xxx.xxx:/var/log/* /mnt/$BKDATE/SERVER05
scp root@xxx.xxx.xxx.xxx:/var/log/* /mnt/$BKDATE/SERVER06
scp root@xxx.xxx.xxx.xxx:/var/log/* /mnt/$BKDATE/SERVER07
scp root@xxx.xxx.xxx.xxx:/var/log/* /mnt/$BKDATE/SERVER08
scp root@xxx.xxx.xxx.xxx:/var/log/* /mnt/$BKDATE/SERVERR01
scp root@xxx.xxx.xxx.xxx:/var/log/* /mnt/$BKDATE/SERVERR02
scp root@xxx.xxx.xxx.xxx:/var/log/* /mnt/$BKDATE/SERVERR03

read -p "The copying process is now completed, press ENETER to unmount the USB...."

# The change of directory is to ensure the drive can be unmounted (if the user ran the bash script within the /mnt/ directory itself 
cd /

# Command to unmount the USB Drive
umount /mnt/

#The USB drive has been unmounted and can be removed
read -p "You can now remove the USB key....press ENTER to exit the script"
exit

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Remote file copy

I facing a problem with Unix command "rcp". I unable to perform a rcp between host machines. I have religiously followed the man pages, but still unable to solve the problem. Do i check for anything to perform this command? Pls help....thanks =) (3 Replies)
Discussion started by: lchunl
3 Replies

2. HP-UX

help me to copy remote file

I want to copy dump generated from oracle database to my local DAT drive. Currently I am copying remote file to local drive thru rcp command and later copy it to local DAT. Pls. help me in this. Thanks Man Mohan email address removed (8 Replies)
Discussion started by: manmohan73
8 Replies

3. Shell Programming and Scripting

copy file from script file to remote computer

hi, i want copy one or group of file from a computer to others, but i have some problem that do not allow me to do this. i do this by scp command like this : scp <file name> root@cpName:destinationAddress but the problem is that it do not it automatically. it means when it is connecting to... (4 Replies)
Discussion started by: MShirzadi
4 Replies

4. Shell Programming and Scripting

Copy a file on remote servers

Hey Unix Gurus, I'm having trouble in copying a file on 5 different servers, first how can you do it locally (i.e without the need to ssh to the server you want to copy the file) and if you need to ssh how do u run a command within that server. Please see my code below(it doesn't work somehow).... (10 Replies)
Discussion started by: sexyTrojan
10 Replies

5. Shell Programming and Scripting

Confirming Remote Copy

Hey guys. I'm knocking up a script, a part of which will be copying some pretty large files to some remote servers. With the size of the files I need to make sure that they don't lose any data / corrupt on the way (it's unlikely, but these are business critical). Obviously I could use the... (2 Replies)
Discussion started by: dlam
2 Replies

6. UNIX for Advanced & Expert Users

Using remote rsync, but copy locally?

I'm looking to use rsync to compare remote files and to copy the diff to a local directory, rather than transfer over the net. The net connection is not fast enough to transfer these files (~1.8TB) and I'd like to sneakernet them instead. Possible? (4 Replies)
Discussion started by: dfbills
4 Replies

7. Shell Programming and Scripting

Copy and run that script in Remote server

Hi All, I need script to perform below task. 1. I have a script in one server and need to copy this script to remote server 2. login in to remote server 3. run the script which i copied to this server. #!/bin/bash read a scp /tmp/script.sh user@hostname:/tmp ssh user@$a ./scirpt.sh ... (2 Replies)
Discussion started by: bapu1981
2 Replies

8. Shell Programming and Scripting

Copy a file from local host to a list of remote hosts --- perl script

Hi friends, i need to prepare a script ( in perl) i have a file called "demo.exe" in my local unix host. i have a list of remote hosts in a file "hosts.txt" now i need to push "demo.exe" file to all the hosts in "hosts.txt" file. for this i need to prepare a script(in perl, but shell... (5 Replies)
Discussion started by: siva kumar
5 Replies

9. UNIX for Dummies Questions & Answers

Remote copy through shellscript

I am using RedHat 4.4 Version Operating System. I want to copy one file from source to destination.I don't want to give a password when I am executing the below shell script. code: #!/bin/bash scp -r file.zip 192.168.1.5:/root/ Here it asking a password to enter,Is there any way give a... (2 Replies)
Discussion started by: kannansoft1985
2 Replies

10. Shell Programming and Scripting

Copy from local to remote

Hi I need a advice for writing simple bash script, I have a file pod.txt which contains source location and remote location: /mnt/infile/20141103/701_0001.png/remote/tmp/pk21730/p0330223723074.png /mnt/infile/20141103/203_0001.png/remote/tmp/pk21731/p0330223723081.png and I must copy ... (6 Replies)
Discussion started by: primo102
6 Replies
SCRIPT(1)						    BSD General Commands Manual 						 SCRIPT(1)

NAME
script -- make typescript of terminal session SYNOPSIS
script [-a] [-c COMMAND] [-f] [-q] [-t] [file] DESCRIPTION
Script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1). If the argument file is given, script saves all dialogue in file. If no file name is given, the typescript is saved in the file typescript. Options: -a Append the output to file or typescript, retaining the prior contents. -c COMMAND Run the COMMAND rather than an interactive shell. This makes it easy for a script to capture the output of a program that behaves differently when its stdout is not a tty. -f Flush output after each write. This is nice for telecooperation: One person does `mkfifo foo; script -f foo' and another can super- vise real-time what is being done using `cat foo'. -q Be quiet. -t Output timing data to standard error. This data contains two fields, separated by a space. The first field indicates how much time elapsed since the previous output. The second field indicates how many characters were output this time. This information can be used to replay typescripts with realistic typing and output delays. The script ends when the forked shell exits (a control-D to exit the Bourne shell (sh(1)), and exit, logout or control-d (if ignoreeof is not set) for the C-shell, csh(1)). Certain interactive commands, such as vi(1), create garbage in the typescript file. Script works best with commands that do not manipulate the screen, the results are meant to emulate a hardcopy terminal. ENVIRONMENT
The following environment variable is utilized by script: SHELL If the variable SHELL exists, the shell forked by script will be that shell. If SHELL is not set, the Bourne shell is assumed. (Most shells set this variable automatically). SEE ALSO
csh(1) (for the history mechanism), scriptreplay(1). HISTORY
The script command appeared in 3.0BSD. BUGS
Script places everything in the log file, including linefeeds and backspaces. This is not what the naive user expects. AVAILABILITY
The script command is part of the util-linux-ng package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/. Linux July 30, 2000 Linux
All times are GMT -4. The time now is 10:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy