Help me to format this data please

Good day,
I have a script on each machine on our network that will say the computer name and the number of updates needed. Then the script will send a file via scp to a network share with the title hostname.local

The contents of the file would be: hostname N (with N being the number of updates needed for that machine) If there are no updates available then it will just show the hostname.

So the network share will end up with a bunch of files called hostname1.local, hostname2.local, etc.. Each file with this type of data.

I need a script to look at all the hostnameX.local files on the share, and to add up all the updates together. Then to email the results to bob@email.com It should actually say the number of machines requiring updates and the total number of updates.

Thanks!

DUPE: output of file from several machines written to network share, then emailed to group.

Actually this is not a duplicate, I am asking a simple way in bash to read multiple files and add all the numbers.. the other post was about putting multiple files into one single file. Basic stuff I'm sure which is why i post in the novice forum.

Instead of asking everyone else to do the work for you why dont you try posing some scripts that you have tried.

Ikon, i'm not sure why you feel you need to moderate this forum and to explain to people how they should ask their questions, but if I had scripts that were working at all I would post them.. i'm confident that using cat on the files in the directory and then grepping for numbers and using expr would give me a sum, but I dont know exactly how to do that and am pressed on time which is why I came here for help, not to be criticized.

This is the 3rd post by you relating to this same script. You have ONLY asked others to do the script for you. If you have no code you can share that you have tried, this must be school work. As you are obviously not a system administrator or programmer.

This forum is here to help people, not do their work. Im sure if you do some searching of the forum you will find some similar topics that can lead you in the correct direction.

Rather than providing the whole solution (as it's been done here among others), why don't we start from the beginning.
Why don't you post one (or two) files from your 'network share' and show us how you 'add up all the updates' (providing the desired output).
Please use the BB codes when posting samples.
I believe some of your earlier threads were in regards to mailing, so that should not be a problem for you now.

I tend to agree with Ikon's comments above. Some people might view them as a bit tough, but he has a good point.

glev2005,

Experts here are not your private employees to do you work for you. They help because they are generous with their time and knowledge. You have a responsibility to actually do your share of the work and not simply ask people here to do all your work for you.

Ok, well just to clarify.. I am not a student, this is not a school project.. I am trying to do some work on a Macintosh Network, and I use BASH, which I am far from an expert in, to do so for the most part. I hear all of your comments, but it is much better to hear them from a moderator, and not some opinionated user who really should just move on if he doesnt like my question. I know quite a lot about some subjects, and am happy to impart knowledge to people of all skill levels, and if i'm not, then I dont and I keep quiet.

That being said, I have narrowed down to getting each number on a separate line, I now have to take the numbers on each line and add them up, I suppose using expr.. Can I please have some help with this?

also, how do i create code tags? <code> ? </code>


my code, data file whatnot goes here
more of the whatnot

[/noparse]
[/code]
here're a number of ways to add numbers from a file (one number per line):

echo `sed -e 's/$/+/' file.txt` 0 | bc
OR
awk '{sum+=$1} END {print sum}' file.txt
OR
echo `tr '\n' '+' < file.txt` 0 |bc
OR
paste -sd+ file.txt |bc
OR
printf "%d\n" $(( `tr -s '\n' '+' < file.txt` 0 ))

IF all the lines were in one file you could do the following to could the second colum.

# cat server.lst
server_a 2
server_b 4
server_c 1

#  awk '{s += $2} END {print s}' server.lst
7

If there are separate files with just a number in them:

# cat servera.server
1

# cat serverb.server
9

# cat test.sh
declare -a FILES
FILES=`ls *.server`
COUNT=0
for PRT in ${FILES[@]}
do
        UPD=`cat $PRT`
        COUNT=$(( $COUNT+$UPD ))
done
echo "Total: $COUNT"

# sh test.sh
Total: 10