script to get file size


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to get file size
# 15  
Old 08-23-2008
thats fine I'll google it. I have some question here, with same code we were using, can we add something to do this..

1, I need to get the .txt files which are greater than 10mb in size from all servers.(i dont need every .txt file)
2, can we point output to file?
3, if we can point to the file, can we send this file to my mail?

basically this is my final requirement.

Thanks once again.
# 16  
Old 08-23-2008
Code:
for host in foo bar baz quux; do
  ssh $host 'ls -l /some/path/*.txt' | awk '$5 > 10000000 { print "'"$host"': $0 }'
done  >file.out

test -s file.out && mailx -s "Files bigger than 10M" you@example.com <file.out

You could try to avoid using a temporary file, but just add "rm file.out" at the end if you don't want to keep it.

Last edited by era; 08-23-2008 at 10:08 PM.. Reason: Change logic to also include host name in generated file
# 17  
Old 08-24-2008
Thanks for your reply,

I'm getting the output, but I can't tell which file belongs to which server. Can we get output like this..

servername: abc
-rw-r--r-- 1 root root 789222 Aug 14 11:03 big.txt
-rw-r--r-- 1 root root 789342 Aug 14 11:03 big.txt
-rw-r--r-- 1 root root 7823252 Aug 14 11:03 big.txt
servername: xyz
-rw-r--r-- 1 root root 789222 Aug 14 11:03 big.txt
-rw-r--r-- 1 root root 789342 Aug 14 11:03 big.txt
-rw-r--r-- 1 root root 7823252 Aug 14 11:03 big.txt
servername: mnc
-rw-r--r-- 1 root root 789222 Aug 14 11:03 big.txt
-rw-r--r-- 1 root root 789342 Aug 14 11:03 big.txt
-rw-r--r-- 1 root root 7823252 Aug 14 11:03 big.txt


Thanks
# 18  
Old 08-24-2008
The awk snippet adds a host: prefix to each line precisely for this reason. I had it the way you describe it at first, but having the information on each line makes the processing somewhat simpler to code. You can post-process it to "lift up" the host before the lines it describes, of course. Are you not seeing the host name at the beginning of every line of ls output?

(Maybe you have an earlier version of the script; I edited it a couple of times after initially posting it. Sorry for the mess.)
# 19  
Old 08-24-2008
No I dont see the server name at the begining of ls output. its giving all together and I dont see any server name.

Thanks
# 20  
Old 08-24-2008
Quote:
Originally Posted by era
Code:
for host in foo bar baz quux; do
  ssh $host 'ls -l /some/path/*.txt' | awk '$5 > 10000000 { print "'"$host"':" $0 }'
done  >file.out

test -s file.out && mailx -s "Files bigger than 10M" you@example.com <file.out

Quote:
Originally Posted by s_linux
No I dont see the server name at the begining of ls output. its giving all together and I dont see any server name.
And the script above is the one you are running, with the $host with the complicated quoting in the awk part? Actually the quoting isn't even right, there's a double-quote missing after the colon. I've edited it into the quoted script above.

You could add echo servername: $host before the ssh but then the logic for finding out whether or not an email should be sent needs to be changed, too; and there will be a servername: header for all servers, regardless of whether they had any files larger than 10M or not. Maybe that would be acceptable, though.

Last edited by era; 08-24-2008 at 12:34 PM.. Reason: Note missing double quote
# 21  
Old 08-24-2008
I just tried with the code...initially it gave me some syntax errors and I could resolve it. but I'm getting only ipaddress.
Here is the code again...

for host in 111.111.111.1111 222.222.222.222; do
ssh $host 'ls -l /some/path/*.txt' | awk '$5 > 40959 { print "'"$host"'";$0 }'
done >file.txt

Thanks again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash Script - File Size

I have a bash script. I need a modification for safety. my original bash script: mv /home/script/backup /home/script/backup2 mysql -u user -ppassword -Ddatabase --batch --skip-column-names -e 'select id, url from videos where url like "%http%" limit 1' | while read id url do youtube-dl... (1 Reply)
Discussion started by: tara123
1 Replies

2. Shell Programming and Scripting

Split file based on file size in Korn script

I need to split a file if it is over 2GB in size (or any size), preferably split on the lines. I have figured out how to get the file size using awk, and I can split the file based on the number of lines (which I got with wc -l) but I can't figure out how to connect them together in the script. ... (6 Replies)
Discussion started by: ssemple2000
6 Replies

3. Shell Programming and Scripting

shell script for getting the file size

Hi can some one please help me how i can get the output i require: My text file "sample.txt" contains the text like below Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_fedora-lv_root 15G 2.6G 12G 19% /hari Filesystem Size ... (3 Replies)
Discussion started by: harimhkr
3 Replies

4. Shell Programming and Scripting

Script to read file size and send email only if size > 0.

Hi Experts, I have a script like $ORACLE_HOME/bin/sqlplus username/password # << ENDSQL set pagesize 0 trim on feedback off verify off echo off newp none timing off set serveroutput on set heading off spool Schemaerrtmp.txt select ' TIMESTAMP COMPUTER NAME ... (5 Replies)
Discussion started by: welldone
5 Replies

5. Shell Programming and Scripting

Not able to make the file size 0 with the mentioned script

#!/bin/sh ########################################################################################################## #This script is being used for AOK application for cleaning up the .out files and zip it under logs directory. # IBM # Created #For pdocap201/pdoca202 .out files for AOK #1.... (3 Replies)
Discussion started by: mridul10_crj
3 Replies

6. Shell Programming and Scripting

Script to check file system size

Dears, the output of this command df -h | tr -s ' ' | cut -f5 -d' ' is capacity 24% 0% 0% 0% 0% 1% 0% 24% 24% 0% 93% 1% (4 Replies)
Discussion started by: xxmasrawy
4 Replies

7. Shell Programming and Scripting

compare file size from a output file from a script

Hi guys, firstly I'm working on SunOS 5.10 Generic_125100-10 sun4u sparc SUNW,Sun-Fire-V240 I've made a script to compress two directory and then send them to an other server via ftp. This is working very well. Inside theis script I decide to log usefull data for troubleshooting in case of... (7 Replies)
Discussion started by: moustik
7 Replies

8. UNIX for Dummies Questions & Answers

file size script

Hi, I am trying to write a script that will send an email to me if the size of a folder is below a certain amount. Does anyone know how to write the if (size < 1000) statement. I know how to send the email? I just need the code for determing a folder size. Thanks, Eric (5 Replies)
Discussion started by: ejbrever
5 Replies

9. Shell Programming and Scripting

Get file size in c shell script?

Hi, I want to use an 'if statement' that will check if a certian file is greater in size than a certain value given by the user, but cannot get it to work. Do you have any ideas how this can be done? Your help is appreciated! (6 Replies)
Discussion started by: Dado
6 Replies

10. UNIX for Dummies Questions & Answers

testing for file size in script

Has anyone got a few tips on how I can test if the file size is 0? I am moving files on a regular basis from one location to another with ftp. The files which are 0 bytes in size we want to discard. Thankyou in advance. (3 Replies)
Discussion started by: Ivo
3 Replies
Login or Register to Ask a Question