Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Bash to append array value to file before copying Post 303039917 by cmccabe on Thursday 17th of October 2019 11:50:13 AM
Old 10-17-2019
So if I understand and am reading the error correctly the * is not expanding on the remote machine? I think this because tee looks good but the terminal doesn't like the *. I am testing this on ubuntu but will use it on centos. Thank you Smilie.


Code:
for ID in "${array[@]}" ; do
      echo "( cd /path/to/${ID}*/*/folder && exec sshpass -f file.txt scp xxx@xxx.xx.xx.xxx:path/to/destination/${ID}-cn_results.png )"
done | tee /tmp/tmp.txt | sshpass -f out.txt ssh -o strictHostKeyChecking=no -t xxxx@xxx.xx.xxx.xx

terminal output
Code:
-bash: line 1: cd: /path/to/ID1*/*/folder: No such file or directory
-bash: line 2: cd: /path/to/ID2*/*/folder: No such file or directory

tee ouput in tmp.txt
Code:
( cd /path/to/ID1*/*/folder && exec sshpass -f file.txt scp xxx@xxx.xx.xx.xxx:path/to/destination/ID1-cn_results.png )
( cd /path/to/ID2*/*/folder && exec sshpass -f file.txt scp xxx@xxx.xx.xx.xxx:path/to/destination/ID2-cn_results.png )

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[bash] redirect (save) array to a file

Hi, I'm trying to write a function that redirects the contents of an array to a file. The array contains the lines of a data file with white space. The function seems to preserve all white space when redirected except that it seems to ignore newlines. As a consequence, the elements of the... (7 Replies)
Discussion started by: ASGR
7 Replies

2. Shell Programming and Scripting

Most reliable way to store file contents in an array in bash

Hi Guys, I have a file which has numbers in it separated by newlines as follows: 1.113 1.456 0.556 0.021 -0.541 -0.444 I am using the following code to store these in an array in bash: FILE14=data.txt ARRAY14=(`awk '{print}' $FILE14`) (6 Replies)
Discussion started by: npatwardhan
6 Replies

3. Shell Programming and Scripting

Noob's 1st...bash-script for copying one file into many

I have one file "file.a.b.c-d.r" that I would like to use to spawn 4 other files: "file.a.b.1-A.r" "file.a.b.1-B.r" "file.a.b.1-C.r" "file.a.b.1-D.r" where the field "c-d" changes into my 1 and A-D. I was doing this manually at the prompt with > cp "file.a.b.c-d.r" "file.a.b.1-A.r" >... (13 Replies)
Discussion started by: WSUToad
13 Replies

4. Shell Programming and Scripting

Bash Scripting - How to grep a file into an array

I have figured out how to grep the file like this: echo `grep $(date +'%Y-%m-%d') Cos-01.csv | cut -d',' -f1` The above line does echo the correct information from the lines in which my search criteria is found. Now I am trying to get that information (Yes, just one column of every line) into... (6 Replies)
Discussion started by: TwelveDays
6 Replies

5. Shell Programming and Scripting

Bash Script Issues (If statement for file copying)

Writing a bash script for use with Geektool, pulls the battery info, and shuffles images around so that an Image geeklet can display the correct expression as the desktop background. (Eventually I intend to make it more intricate, based on more variables, and add more expressions) I'm extremely... (1 Reply)
Discussion started by: The_Ardly374
1 Replies

6. UNIX for Dummies Questions & Answers

Passing values from file into array in Bash

Hi, I'm trying to write a bash script that takes a file and passes each line from the file into an array with elements separated by column. For example: Sample file "file1.txt": 1 name1 a first 2 name2 b second 3 name3 c third and have arrays such as: line1 = ( "1" "name1" "a"... (3 Replies)
Discussion started by: ShiGua
3 Replies

7. Shell Programming and Scripting

Append awk results into file or array

for a in {1..100} do awk '{ sum+=$a} END {print sum}' a=$a file1 > file2 done I know I will get only one number if following the code above, how can I get 100 sum numbers in file2? (2 Replies)
Discussion started by: wanliushao
2 Replies

8. Shell Programming and Scripting

Ftp with bash, append file where left off

I'm working on a bash script to finish uploading a file. I need a way to get $filesize so that "restart $filesize" will work. Here is my script: ftp -n -v <<END_SCRIPT open ftp.$domain user $user@$domain $password size $file restart $filesize put $file quit END_SCRIPTWayne Sallee... (9 Replies)
Discussion started by: WayneSallee
9 Replies

9. Shell Programming and Scripting

Bash append values if keywords are present in the file

Hi Team, i have a web ui where user will be passing values and the output will be saved to a file say test with the following contents . These below mentioned values will change according to the user_input Just gave here one example Contents of file test is given below Gateway... (7 Replies)
Discussion started by: venkitesh
7 Replies

10. OS X (Apple)

Create a bash array from a flat file of whitespaces only.

Hi guys and gals... MacBook Pro. OSX 10.13.2, default bash terminal. I have a flat file 1920 bytes in size of whitespaces only. I need to put every single whitespace character into a bash array cell. Below are two methods that work, but both are seriously ugly. The first one requires that I... (7 Replies)
Discussion started by: wisecracker
7 Replies
SSHPASS(1)							Sshpass User Manual							SSHPASS(1)

NAME
sshpass - noninteractive ssh password provider SYNOPSIS
sshpass [-ffilename|-dnum|-ppassword|-e] [options] command arguments DESCRIPTION
This manual page documents the sshpass command. sshpass is a utility designed for running ssh using the mode referred to as "keyboard-interactive" password authentication, but in non- interactive mode. ssh uses direct TTY access to make sure that the password is indeed issued by an interactive keyboard user. Sshpass runs ssh in a dedicated tty, fooling it into thinking it is getting the password from an interactive user. The command to run is specified after sshpass' own options. Typically it will be "ssh" with arguments, but it can just as well be any other command. The password prompt used by ssh is, however, currently hardcoded into sshpass. Options If no option is given, sshpass reads the password from the standard input. The user may give at most one alternative source for the pass- word: -ppassword The password is given on the command line. Please note the section titled "SECURITY CONSIDERATIONS". -ffilename The password is the first line of the file filename. -dnumber number is a file descriptor inherited by sshpass from the runner. The password is read from the open file descriptor. -e The password is taken from the environment variable "SSHPASS". SECURITY CONSIDERATIONS
First and foremost, users of sshpass should realize that ssh's insistance on only getting the password interactively is not without reason. It is close to impossible to securely store the password, and users of sshpass should consider whether ssh's public key authentication pro- vides the same end-user experience, while involving less hassle and being more secure. The -p option should be considered the least secure of all of sshpass's options. All system users can see the password in the command line with a simple "ps" command. Sshpass makes a minimal attempt to hide the password, but such attempts are doomed to create race conditions without actually solving the problem. Users of sshpass are encouraged to use one of the other password passing techniques, which are all more secure. In particular, people writing programs that are meant to communicate the password programatically are encouraged to use an anonymous pipe and pass the pipe's reading end to sshpass using the -d option. RETURN VALUES
As with any other program, sshpass returns 0 on success. In case of failure, the following return codes are used: 1 Invalid command line argument 2 Conflicting arguments given 3 General runtime error 4 Unrecognized response from ssh (parse error) 5 Invalid/incorrect password 6 Host public key is unknown. sshpass exits without confirming the new key. In addition, ssh might be complaining about a man in the middle attack. This complaint does not go to the tty. In other words, even with sshpass, the error message from ssh is printed to standard error. In such a case ssh's return code is reported back. This is typically an unimaginative (and non-informative) "255" for all error cases. EXAMPLES
Run rsync over SSH using password authentication, passing the password on the command line: rsync --rsh='sshpass -p 12345 ssh -l test' host.example.com:path . To do the same from a bourne shell script in a marginally less exposed way: SSHPASS=12345 rsync --rsh='sshpass -e ssh -l test' host.example.com:path . BUGS
Sshpass is in its infancy at the moment. As such, bugs are highly possible. In particular, if the password is read from stdin (no password option at all), it is possible that some of the input aimed to be passed to ssh will be read by sshpass and lost. Sshpass utilizes the pty(7) interface to control the TTY for ssh. This interface, at least on Linux, has a misfeature where if no slave file descriptors are open, the master pty returns EIO. This is the normal behavior, except a slave pty may be born at any point by a pro- gram opening /dev/tty. This makes it impossible to reliably wait for events without consuming 100% of the CPU. Over the various versions different approaches were attempted at solving this problem. Any given version of sshpass is released with the belief that it is working, but experience has shown that these things do, occasionally, break. This happened with OpenSSH version 5.6. As of this writing, it is believed that sshpass is, again, working properly. Lingnu Open Source Consulting August 6, 2011 SSHPASS(1)
All times are GMT -4. The time now is 01:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy