Sponsored Content
Top Forums Shell Programming and Scripting ksh scripting SSH to Compare File Sizes Post 303025349 by Abstract3000 on Wednesday 31st of October 2018 08:39:00 AM
Old 10-31-2018
I appreciate the advice, I was kind of thinking the same thing myself while looking at it that I needed some sort of for loop to iterate through the servers executing the same command while storing file locations in variables and simply comparing each server to the 1st. I don't really have any idea of how i could apply a for loop to ssh multiple servers that were in an Array for instance. Though I did rework the code a bit and came up with the following solution, though you couldn't be as specific in your output you could easily spot an error.

Code:
#!/bin/ksh


FILE1=/root/directory1/files/file1.fil
FILE2=/root/directory2/files/file2.fil
FILESZ1==$(stat -c%s "$FILE1")
FILESZ2==$(stat -c%s "$FILE2")

filecheck() {
CHKFILE1=$(stat -c%s "$FILE1")
CHKFILE2=$(stat -c%s "$FILE2")
if [[ $FILESZ1 = $CHKFILE1 ]]; then
	print "file sizes match"
else
	print "file sizes do not match"
fi
if [[ $FILESZ2 = $CHKFILE3 ]]; then
	print "file sizes match"
else
	print "file sizes do not match"
fi
}

ssh user@server2 "$(typeset -f filecheck); filecheck;
ssh user@server3 "$(typeset -f filecheck); filecheck;
ssh user@server4 "$(typeset -f filecheck); filecheck;

Would the following code do the trick or am I missing something?
Thanks for the suggestions.
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
ExtUtils::Manifest(3pm) 				 Perl Programmers Reference Guide				   ExtUtils::Manifest(3pm)

NAME
ExtUtils::Manifest - utilities to write and check a MANIFEST file SYNOPSIS
use ExtUtils::Manifest qw(...funcs to import...); mkmanifest(); my @missing_files = manicheck; my @skipped = skipcheck; my @extra_files = filecheck; my($missing, $extra) = fullcheck; my $found = manifind(); my $manifest = maniread(); manicopy($read,$target); maniadd({$file => $comment, ...}); DESCRIPTION
Functions ExtUtils::Manifest exports no functions by default. The following are exported on request mkmanifest mkmanifest(); Writes all files in and below the current directory to your MANIFEST. It works similar to the result of the Unix command find . > MANIFEST All files that match any regular expression in a file MANIFEST.SKIP (if it exists) are ignored. Any existing MANIFEST file will be saved as MANIFEST.bak. manifind my $found = manifind(); returns a hash reference. The keys of the hash are the files found below the current directory. manicheck my @missing_files = manicheck(); checks if all the files within a "MANIFEST" in the current directory really do exist. If "MANIFEST" and the tree below the current directory are in sync it silently returns an empty list. Otherwise it returns a list of files which are listed in the "MANIFEST" but missing from the directory, and by default also outputs these names to STDERR. filecheck my @extra_files = filecheck(); finds files below the current directory that are not mentioned in the "MANIFEST" file. An optional file "MANIFEST.SKIP" will be consulted. Any file matching a regular expression in such a file will not be reported as missing in the "MANIFEST" file. The list of any extraneous files found is returned, and by default also reported to STDERR. fullcheck my($missing, $extra) = fullcheck(); does both a manicheck() and a filecheck(), returning then as two array refs. skipcheck my @skipped = skipcheck(); lists all the files that are skipped due to your "MANIFEST.SKIP" file. maniread my $manifest = maniread(); my $manifest = maniread($manifest_file); reads a named "MANIFEST" file (defaults to "MANIFEST" in the current directory) and returns a HASH reference with files being the keys and comments being the values of the HASH. Blank lines and lines which start with "#" in the "MANIFEST" file are discarded. maniskip my $skipchk = maniskip(); my $skipchk = maniskip($manifest_skip_file); if ($skipchk->($file)) { .. } reads a named "MANIFEST.SKIP" file (defaults to "MANIFEST.SKIP" in the current directory) and returns a CODE reference that tests whether a given filename should be skipped. manicopy manicopy(\%src, $dest_dir); manicopy(\%src, $dest_dir, $how); Copies the files that are the keys in %src to the $dest_dir. %src is typically returned by the maniread() function. manicopy( maniread(), $dest_dir ); This function is useful for producing a directory tree identical to the intended distribution tree. $how can be used to specify a different methods of "copying". Valid values are "cp", which actually copies the files, "ln" which creates hard links, and "best" which mostly links the files but copies any symbolic link to make a tree without any symbolic link. "cp" is the default. maniadd maniadd({ $file => $comment, ...}); Adds an entry to an existing MANIFEST unless its already there. $file will be normalized (ie. Unixified). UNIMPLEMENTED MANIFEST A list of files in the distribution, one file per line. The MANIFEST always uses Unix filepath conventions even if you're not on Unix. This means foo/bar style not fooar. Anything between white space and an end of line within a "MANIFEST" file is considered to be a comment. Any line beginning with # is also a comment. Beginning with ExtUtils::Manifest 1.52, a filename may contain whitespace characters if it is enclosed in single quotes; single quotes or backslashes in that filename must be backslash-escaped. # this a comment some/file some/other/file comment about some/file 'some/third file' comment MANIFEST.SKIP The file MANIFEST.SKIP may contain regular expressions of files that should be ignored by mkmanifest() and filecheck(). The regular expressions should appear one on each line. Blank lines and lines which start with "#" are skipped. Use "#" if you need a regular expression to start with a "#". For example: # Version control files and dirs. RCS CVS ,v$ B.svn # Makemaker generated files and dirs. ^MANIFEST. ^Makefile$ ^blib/ ^MakeMaker-d # Temp, old and emacs backup files. ~$ .old$ ^#.*#$ ^.# If no MANIFEST.SKIP file is found, a default set of skips will be used, similar to the example above. If you want nothing skipped, simply make an empty MANIFEST.SKIP file. In one's own MANIFEST.SKIP file, certain directives can be used to include the contents of other MANIFEST.SKIP files. At present two such directives are recognized. #!include_default This inserts the contents of the default MANIFEST.SKIP file #!include /Path/to/another/manifest.skip This inserts the contents of the specified external file The included contents will be inserted into the MANIFEST.SKIP file in between #!start included /path/to/manifest.skip and #!end included /path/to/manifest.skip markers. The original MANIFEST.SKIP is saved as MANIFEST.SKIP.bak. EXPORT_OK &mkmanifest, &manicheck, &filecheck, &fullcheck, &maniread, and &manicopy are exportable. GLOBAL VARIABLES $ExtUtils::Manifest::MANIFEST defaults to "MANIFEST". Changing it results in both a different "MANIFEST" and a different "MANIFEST.SKIP" file. This is useful if you want to maintain different distributions for different audiences (say a user version and a developer version including RCS). $ExtUtils::Manifest::Quiet defaults to 0. If set to a true value, all functions act silently. $ExtUtils::Manifest::Debug defaults to 0. If set to a true value, or if PERL_MM_MANIFEST_DEBUG is true, debugging output will be produced. DIAGNOSTICS
All diagnostic output is sent to "STDERR". "Not in MANIFEST:" file is reported if a file is found which is not in "MANIFEST". "Skipping" file is reported if a file is skipped due to an entry in "MANIFEST.SKIP". "No such file:" file is reported if a file mentioned in a "MANIFEST" file does not exist. "MANIFEST:" $! is reported if "MANIFEST" could not be opened. "Added to MANIFEST:" file is reported by mkmanifest() if $Verbose is set and a file is added to MANIFEST. $Verbose is set to 1 by default. ENVIRONMENT
PERL_MM_MANIFEST_DEBUG Turns on debugging SEE ALSO
ExtUtils::MakeMaker which has handy targets for most of the functionality. AUTHOR
Andreas Koenig "andreas.koenig@anima.de" Maintained by Michael G Schwern "schwern@pobox.com" within the ExtUtils-MakeMaker package and, as a separate CPAN package, by Randy Kobes "r.kobes@uwinnipeg.ca". perl v5.18.2 2013-11-04 ExtUtils::Manifest(3pm)
All times are GMT -4. The time now is 01:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy