ksh scripting SSH to Compare File Sizes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh scripting SSH to Compare File Sizes
# 8  
Old 10-31-2018
I like that consequent application of arrays; that might simplify my approach and even offer simple extensions...
# 9  
Old 11-01-2018
Thanks for the other approach, I really appreciate you both taking the time to give an example, I am going to play around with both of these and see what I can come up with Smilie
# 10  
Old 11-08-2018
So messing around with both Methods I have come to find out that "Stat" does not work with the Version of AIX I'm on but Instead I must use "wc"
So I have improvised on the line

Code:
set -A FS$i $(ssh ${HOSTS[i]} "wc -c ${FILES[@]} | awk '{print $1}'")

I have tested the line starting with ssh and it works just fine but when running the Script i get the following error
Code:
"i++: 0403-053 Expression is not complete; more tokens expected

" I'm almost positive that line is the issue as it goes to ssh, pulls the server disclaimer but continues no further. I have tried putting the command in Double Quotations as Well as the
Code:
'{print $1}'

in double apostrophes, not sure what I'm still missing here?

Last edited by RudiC; 11-08-2018 at 12:20 PM..
# 11  
Old 11-08-2018
Does your ksh version understand the (( ... )) "Arithmetic Expansion"?
Did you check for the istat command?
Did you assess using ls -l's size field (one inode access) against counting every single byte in a file?
# 12  
Old 11-08-2018
Code:
set -A FS$i $(ssh ${HOSTS[i]} "wc -c ${FILES[@]} | awk '{print \$1}'")

# 13  
Old 11-09-2018
Code:
i=0 while [[ $i -lt ${#HOSTS[@]} ]]; do    set -A FS$i $(ssh ${HOSTS[i]} "stat -c%s ${FILES[@]}")    ((i++)) done


Is this not the problem for ksh? I will have to give that a shot.


Code:
set -A FS$i $(ssh ${HOSTS[i]} "wc -c ${FILES[@]} | awk '{print \$1}'")


Whats The Significance of the Back Slash here?


as for the Version of Ksh, I'm pretty sure it predates the paleolithic era, as for the the istat (inode) command I have not tried that, looked at it previously but couldn't find any sort of modifiers or description on how to extract just the file size from IBM's site so wasn't positive that was an option. and for assessing the "ls -l" are you referring to something like this?
Code:
$ set -A FS$i $(ssh ${HOSTS[i]} "ls -lah ${FILES[@]} | awk '{print $5}'")

Moderator's Comments:
Mod Comment Please use code tags NOT quote tags around code. Thank you.
# 14  
Old 11-09-2018
Quote:
Originally Posted by Abstract3000
as for the Version of Ksh, I'm pretty sure it predates the paleolithic era, as for the the istat (inode) command I have not tried that, looked at it previously but couldn't find any sort of modifiers or description on how to extract just the file size from IBM's site so wasn't positive that was an option. and for assessing the "ls -l" are you referring to something like this?
Code:
$ set -A FS$i $(ssh ${HOSTS[i]} "ls -lah ${FILES[@]} | awk '{print $5}'")

Same problem as before. Without escaping, $5 will evaluate before ssh happens.

Code:
set -A FS$i $(ssh ${HOSTS[i]} "ls -lah ${FILES[@]} | awk '{print \$5}'")

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ksh: how compare content of a file with an other array

Hi, I created a skript in ksh which generate a file with semicolon as separator, this is an example of the file a created: example content file: hello;AAAA;2014-08-17 hello;BBBB;2014-08-17 hello;CCCC;2014-08-17 I would need to compare the content in of the second column of this file... (3 Replies)
Discussion started by: jmartin
3 Replies

2. UNIX for Dummies Questions & Answers

ksh scripting, skip server if asks for password with SSH

Hi, I am running a script that connets to a list of servers with SSH and runs a command but I have some servers that are asking for password (authorized keys is not configured properly). Is there any way to do so that if I get a prompt for password just skip that entry? my script: ... (1 Reply)
Discussion started by: galuzan
1 Replies

3. Shell Programming and Scripting

Using csh / awk / sed to compare database sizes in a txt file

Hello, I have an output file showing database sizes across the 3 environments that I use (LIVE, TEST & DEVELOPMENT). I am trying to write a script that lets me know if the size of a db on one environment is different to its corresponding db on the other environments. Here is an example... (4 Replies)
Discussion started by: stevie_g
4 Replies

4. Shell Programming and Scripting

Script to compare file sizes

I need to write a bash script larger X Y that compares the sizes of two specified files X and Y, and reports which file is larger. For example, if X is larger, the output should be "File X is larger", while if Y is larger, the output should be "File Y is larger". If the files are exactly the... (3 Replies)
Discussion started by: julia_21436
3 Replies

5. UNIX for Dummies Questions & Answers

Compare two file sizes.

Hi everyone! I need to compare two file sizes. One of them (size) will be stored in a flat file and the other coming from a listed file. I can now get the first file size using: SIZE=`ls -l $DOCTYPE | awk '{print $5}'` 1. How can I store this value in a flat file? 2. How... (2 Replies)
Discussion started by: mrreds
2 Replies

6. HP-UX

compare file percent sizes

I need to get a file size and compare it to a previous day file size. If it's larger or smaller by 50 percent I'll replace the new with the old. I know how to get the file sizes but do not know how to calculate if it's 50 percent difference. Thanks for your help. (2 Replies)
Discussion started by: jkuchar747
2 Replies

7. Shell Programming and Scripting

KSH: Compare variable to $1 in an input file

Hello, I am working with KSH on AIX and I have 2 files generated from different sources... as seen below: FILE1 FILE2 AAA AAA@ABS0001C BBB BBB@ABS0003D CCC CCC@ABS0023A DDD DDD@ABC0145D EEE EEE@ABS0090A FFF FFF@ABS0002A GGG GGG@ABC0150D HHH FILE1 is main main data source,... (4 Replies)
Discussion started by: right_coaster
4 Replies

8. Shell Programming and Scripting

how to compare file sizes

hi ls -l * | sed 's/\+/ /g' | cut -f5 -d " " >out1 ls -l * | sed 's/\+/ /g' | cut -f5 -d " " >out2 diff out1 out2 i tried this it will work fine and i can see difference but i need a script which should neglect, if the difference b/w files is small and it should display... (5 Replies)
Discussion started by: revenna
5 Replies

9. Shell Programming and Scripting

to compare total directory structure and get sizes of all f on two different servers

Hello every one, Iam newbie to this forum and shell programming &scripting. i needed to compare each and every folder of two separate servers. Actually I have copied some directory structure from one server to second server, to build on second server the files all should be copied... (3 Replies)
Discussion started by: mannam srinivas
3 Replies

10. Shell Programming and Scripting

compare file sizes

Is there a command that will return the name of the largest file within a directory? If so, can I set the returned filename into a variable? (4 Replies)
Discussion started by: joli
4 Replies
Login or Register to Ask a Question