Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8572521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:02:01+00:00 2026-06-11T19:02:01+00:00

I wrote this script to automate wgets from my different servers, between each other,

  • 0

I wrote this script to automate wgets from my different servers, between each other, and to output the results to a log file, and email them to me. Part of the reason I am sharing this is so that other people can use the solution for themselves.

I’ve placed the file in cron.weekly so it sends me weekly emails.

Btw. I am an absolute novice, this was the first script I wrote by learning from this site.

Script is as follows:
I have done some minor commenting from my side as well.

#!/bin/sh
#wget -verbose -tries -timeout -dontcreatedirectories -dontsaveanything  http://x  output text to file

# automating apt-get update and upgrade so it runs weekly
apt-get update
apt-get upgrade -y

# this is where the logs will be stored
cd /var/log

# create a tmp file and if it is left behind from earlier results, empty it out
echo -e "\n" > wget.tmp

# these are the header texts for the results 
echo "***************" >> $(hostname -s)"-wget-SUMMARY-"$(date "+%b%d_%Y" | tr A-Z a-z).log
echo "WGET SCHEDULES" >> $(hostname -s)"-wget-SUMMARY-"$(date "+%b%d_%Y" | tr A-Z a-z).log
echo "***************" >> $(hostname -s)"-wget-SUMMARY-"$(date "+%b%d_%Y" | tr A-Z a-z).log

# this will make note of the time the tests are started
date "+START OF WGETS SCHEDULE at %c"  >> $(hostname -s)"-wget-SUMMARY-"$(date "+%b%d_%Y" | tr A-Z a-z).log
echo "\n" >> $(hostname -s)"-wget-SUMMARY-"$(date "+%b%d_%Y" | tr A-Z a-z).log
echo "\n" >> $(hostname -s)"-wget-SUMMARY-"$(date "+%b%d_%Y" | tr A-Z a-z).log

# up to 10 servers to wget from
echo "Server #1" >> $(hostname -s)"-wget-SUMMARY-"$(date "+%b%d_%Y" | tr A-Z a-z).log
wget -v -r -t 2 -T 7 -nd -O /dev/null http://servername/file 2>> wget.tmp
grep -i 'Length\|connect\|100%\|saved\|failed\|Error' wget.tmp >> $(hostname -s)"-wget-SUMMARY-"$(date "+%b%d_%Y" | tr A-Z a-z).log
rm -f wget.tmp
echo "\n" >> $(hostname -s)"-wget-SUMMARY-"$(date "+%b%d_%Y" | tr A-Z a-z).log

.
continues till
.

echo "Server #10" >> $(hostname -s)"-wget-SUMMARY-"$(date "+%b%d_%Y" | tr A-Z a-z).log
wget -v -r -t 2 -T 7 -nd -O /dev/null http://servername/file 2>> wget.tmp
grep -i 'Length\|connect\|100%\|saved\|failed\|Error' wget.tmp >> $(hostname -s)"-wget-SUMMARY-"$(date "+%b%d_%Y" | tr A-Z a-z).log
rm -f wget.tmp
echo "\n" >> $(hostname -s)"-wget-SUMMARY-"$(date "+%b%d_%Y" | tr A-Z a-z).log

# record the end time of tests
echo "***************" >> $(hostname -s)"-wget-SUMMARY-"$(date "+%b%d_%Y" | tr A-Z a-z).log
date "+END OF WGETS SCHEDULE at %c"  >> $(hostname -s)"-wget-SUMMARY-"$(date "+%b%d_%Y" | tr A-Z a-z).log

#mail results to yourself
echo "Subject: $(hostname -s| tr a-z A-Z)"  Wget Results v.2.0 Sendmail  "$(date +%x)"      ----   "$(date "+%A")"    "$(date "+%X")   ("$(date "+%Z")")  :::  Week "$(date "+%V")"  """ | cat -  $(hostname -s)"-wget-SUMMARY-"$(date "+%b%d_%Y" | tr A-Z a-z).log | /usr/lib/sendmail -t myemailaddress@host.x

ideally, i would like to not limit myself to x # of servers, but so long as there is text in file servers.list (by included ‘.’ in the filename i can store it in cron.weekly and it will not be processed). So for each server, write server #, and process the wget, output to file, grep to log file. It would be best if the servers.list file was formatted

hostname filename store/to
.
.
hostname filename store/to

Example:

msn.robots.ua 100mb.test /dev/null
justme.cov ratings.xlsx  /srv/storage/latest

the mails look like

Subject: Servername Wget Results v.2.0 Sendmail 09/09/12 —- Sunday 04:59:21 (MSK) ::: Week 36


WGET SCHEDULES


START OF WGETS SCHEDULE at Sun Sep 9 04:52:00 2012

Server #1
Connecting to xxx.xxxxxx.com|ip.ip.ip.ip|:80… connected.
Length: 104857600 (100M) [text/plain]
102350K ………. ………. ………. ………. ……….100% 5.73M 0s
102400K 100% 0.00 =25s
2012-09-09 04:52:27 (4.07 MB/s) – `/dev/null’ saved [104857600/104857600]
.
.


END OF WGETS SCHEDULE at Sun Sep 9 04:59:21 2012


So my /var/log ends up storing the files such as wordpress-wget-SUMMARY-sep24_2012.log as an example file name. Problem is maintaining it is becoming a problem, servers change, so I would like to just update the servers list in one location and let them deal with it all themselves. Prior to execution it would download the new servers.list and the rest is done.

Mail is working output to log file is working, it is all working, just needs a tiny bit of tweaking.

Ty ! Ty ! Ty for reading .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:02:02+00:00Added an answer on June 11, 2026 at 7:02 pm

    If I’m duplicating your question right, you want to replace out the fact that you can only do 10 servers and want to pull the data from a file instead of having to fix it in the script if anything changes. Based on that duplication, here is what I suggest:

    In your server.list file, | delimit it, I’ll explain why after the code snippit. So your server.list file would look like:

    msn.robots.ua|100mb.test|/dev/null
    justme.cov|ratings.xlsx|/srv/storage/latest
    

    With this set up, you can put a for loop in your bash script with your duplicative code in the middle like this:

        for conf in $(cat server.list); do
            server=`echo $conf | cut -d"|" -f1;`
            filename=`echo $conf | cut -d"|" -f2;`
            storeto=`echo $conf | cut -d"|" -f3;`
    
            ... the rest of your code goes here using the above variables ...
    
        done
    

    If you use spaces as the delimiter in your file then $conf in each iteration will be only each space separated value, instead of getting the line and then splitting it up.

    There is probably a more elegant way to do this with awk, but this would work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this script which counts occurrences of particular pattern in a given file.
$(function(){ $('a').each(function(){ var x=this.href; this.href=www.somesitename.com/filter+this.href; }); }); i wrote the above jQuery script to
i write a script to list my file from Update directory with this option:
I wrote this script to for a contact form on my website, everything works
Can someone explain why this script throws an exception? $byteArray = @(1,2,3) write-Output (
Update: I wrote a working script that finishes this job in a reasonable length
I wrote a python script to automate turning Sweave/LaTeX documents into PDFs. Here's the
I'm doing some script in Powershell to automate a task. This script is going
I wrote this script to delete rows which contain a value in column C
This script cannot find bannersize unless I write <div id=bannersize></div> before the javascript. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.