Sponsored Content
Top Forums Shell Programming and Scripting while loop to copy on failure Post 302150205 by porter on Monday 10th of December 2007 03:17:08 PM
Old 12-10-2007
Quote:
Originally Posted by jjinno
Code:
do {
  scp veryOriginalName.1 root@myComp:/tmp
  scp veryOriginalName.2 root@myComp:/tmp
  scp veryOriginalName.3 root@myComp:/tmp
  scp veryOriginalName.4 root@myComp:/tmp

  VAR = ssh root@myComp "ls -l /tmp/veryOriginalName.*" | grep "-" | wc -l
} while {
  VAR != 4
}

Why not use the error code returned by scp to indicate the success or failure of the operation?

Also, you can transfer multiple at the same time which would save time on connection and negotiation....

Code:
scp veryOriginalName.1 \
       veryOriginalName.2 \
       veryOriginalName.3 \
       veryOriginalName.4 root@myComp:/tmp/
if test "$?" = "0"
then
     echo success
     VAR = `ssh root@myComp "ls -l /tmp/veryOriginalName.*" | grep "-" | wc -l`
else
     echo failure
fi

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unzip, copy, and delete loop

Hey there, I am trying to move zipped text files from a remote server to a remote tape storage facility, through my home directory. What I want to do is get the zip file (using scp), unzip it, copy the output text file which was inside (using rfcp) to the tape storage server, and then delete... (3 Replies)
Discussion started by: spyne
3 Replies

2. Shell Programming and Scripting

copy command failure

A cp command failure occured on our production system. A shell script copies a source file to a temporary directory - cp <source file on mount point 1> <dest path on mount point 2> The same script ran successfully for another file, about 3mins after the failure. The script did not have a... (1 Reply)
Discussion started by: mynix
1 Replies

3. Shell Programming and Scripting

Loop to copy like files

Hi, I need to write a script that copies all .zip files in the subdirectories of ~100 folders. No clue how to write a loop that goes into each folder, searches for a .zip file, and copies it and extracts it to a unique location. I imagine something like cp -f /home/folder1/*.zip... (6 Replies)
Discussion started by: nez
6 Replies

4. Shell Programming and Scripting

Loop folders, delete files, copy new ones

Folks, I am hopeful that you may be able to help me out with writing a script that can be run nightly (as cron?) to loop through all subfolders within the "/media" directory, delete all of the files in each of them, and then copy in all of the files from the "/home//sansa" directory to each of... (6 Replies)
Discussion started by: acraig
6 Replies

5. UNIX Desktop Questions & Answers

Copy all files in 1 directory to another usinge for-in loop

I was looking to get some help with copying files in one directory to another using a for-in loop. My script file is called copyfile and here is what I have: for file in $(ls -a $1) do cp $file ~/dir-2 done When I run copyfile dir-1 this is what I get cp: omitting directory `.'... (1 Reply)
Discussion started by: Trinimini
1 Replies

6. Shell Programming and Scripting

Loop through text file > Copy Folder > Edit XML files in bulk?

I have a text file which contains lines in this format - it contains 105 lines in total, but I'm just putting 4 here to keep it short: 58571,east_ppl_ppla_por 58788,east_pcy_hd_por 58704,east_pcy_ga_por 58697,east_pcy_pcybs_por It's called id_key.txt I have a sample folder called... (9 Replies)
Discussion started by: biscuitcreek
9 Replies

7. Shell Programming and Scripting

KSH Script -- loop and data copy question

I am trying to write a script that will allow me to train others with commands that I run manually by only allowing the exact command before continuing onto the next set of commands. Here is where I come into an issue. I have changed the directories for this post. Software we run creates files... (2 Replies)
Discussion started by: hurtzdonut
2 Replies

8. UNIX for Dummies Questions & Answers

boot up failure unix sco after power failure

hi power went out. next day unix sco wont boot up error code 303. any help appreciated as we are clueless. (11 Replies)
Discussion started by: fredthayer
11 Replies

9. Shell Programming and Scripting

Failure using regex with awk in 'while read file' loop

I have a file1.txt with several 100k lines, each of which has a column 9 containing one of 60 "label" identifiers. Using an labels.txt file containing a list of labels, I'd like to extract 200 random lines from file1.txt for each of the labels in index.txt. Using a contrived mini-example: $ cat... (8 Replies)
Discussion started by: pathunkathunk
8 Replies

10. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies
scp(1)								   User Commands							    scp(1)

NAME
scp - secure copy (remote file copy program) SYNOPSIS
scp [-pqrvBC46] [-F ssh_config] [-S program] [-P port] [-c cipher] [-i identity_file] [-o ssh_option] [ [user@]host1:]file1 []... [ [user@]host2:]file2 DESCRIPTION
The scp utility copies files between hosts on a network. It uses ssh(1) for data transfer, and uses the same authentication and provides the same security as ssh(1). Unlike rcp(1), scp will ask for passwords or passphrases if they are needed for authentication. Any file name may contain a host and user specification to indicate that the file is to be copied to/from that host. Copies between two remote hosts are permitted. OPTIONS
The following options are supported: -4 Forces scp to use IPv4 addresses only. -6 Forces scp to use IPv6 addresses only. -B Selects batch mode. (Prevents asking for passwords or passphrases.) -c cipher Selects the cipher to use for encrypting the data transfer. This option is directly passed to ssh(1). -C Compression enable. Passes the -C flag to ssh(1) to enable compression. -F ssh_config Specifies an alternative per-user configuration file for ssh(1.). -i identity_file Selects the file from which the identity (private key) for RSA authentication is read. This option is directly passed to ssh(1). -o ssh_option The given option is directly passed to ssh(1). -p Preserves modification times, access times, and modes from the original file. -P port Specifies the port to connect to on the remote host. Notice that this option is written with a capital `P', because -p is already reserved for preserving the times and modes of the file in rcp(1). -q Disables the progress meter. -r Recursively copies entire directories. -S program Specifies the name of the program to use for the encrypted connection. The program must understand ssh(1) options. -v Verbose mode. Causes scp and ssh(1) to print debugging messages about their progress. This is helpful in debugging con- nection, authentication, and configuration problems. OPERANDS
The following operands are supported: host1, host2,... The name(s) of the host from or to which the file is to be copied. file1, file2,... The file(s) to be copied. EXIT STATUS
The following exit values are returned: 0 Successful completion. 1 An error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWsshu | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ SEE ALSO
rcp(1), ssh(1), ssh-add(1), ssh-agent(1), ssh-keygen(1), sshd(1M), ssh_config(4), attributes(5) NOTES
Generally, use of scp with password or keyboard-interactive authentication method and two remote hosts does not work. It does work with either the pubkey, hostbased or gssapi-keyex authentication method. For the pubkey authentication method, either private keys not pro- tected by a passphrase, or an explicit ssh agent forwarding have to be used. The gssapi-keyex authentication method works with the ker- beros_v5 GSS-API mechanism, but only if the GSSAPIDelegateCredentials option is enabled. SunOS 5.11 22 Jun 2007 scp(1)
All times are GMT -4. The time now is 11:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy