You are not logged in.

#1 2022-03-03 01:41:54

amghwk
Member
Registered: 2020-05-23
Posts: 43

[SOLVED] Help clean-up personal mirror update script

Hi, I have the following script to update the mirrors:

~/.scripts/updatemirrors.sh wrote:

#! /bin/bash
date >> /home/amghwk/.scripts/mirrorlist-backup
cat /etc/pacman.d/mirrorlist >> /home/amghwk/.scripts/mirrorlist-backup
reflector -c TH > /etc/pacman.d/mirrorlist
reflector -c SG >> /etc/pacman.d/mirrorlist
reflector -c HK >> /etc/pacman.d/mirrorlist
reflector -c VN >> /etc/pacman.d/mirrorlist
reflector -c TW >> /etc/pacman.d/mirrorlist
reflector -c JP >> /etc/pacman.d/mirrorlist
reflector -c KR >> /etc/pacman.d/mirrorlist

I would like to keep track of when I updated the mirrors and place the backup history in the mirrorlist-backup file. How do I pass a carriage return or something like

**************************************************

Backup created on <date command output here> 

**************************************************

with clear carriage return spaces above and below this output?

Thank you.

Last edited by amghwk (2022-03-13 01:04:24)

Offline

#2 2022-03-03 02:15:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,484
Website

Re: [SOLVED] Help clean-up personal mirror update script

First, why are you running reflector half a dozen times?  Just use one call:

reflector -c th,sg,hk,vn,tw,jp,kr --sort country

But to directly answer your question, you can echo for each line, or printf to specify exactly what you want, or in this case perhaps cat would work well with a here-document:

cat <<EOF >> /home/amghwk/.scripts/mirrorlist-backup
**************************************************

Backup created on $(date) 

**************************************************
EOF
cat /etc/pacman.d/mirrorlist >> /home/amghwk/.scripts/mirrorlist-backup

reflector -c th,sg,hk,vn,tw,jp,kr --sort country > /etc/pacman.d/mirrorlist

You may want to follow the first couple of tutorials here to learn how to use basic shell commands.

Last edited by Trilby (2022-03-03 02:17:06)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2022-03-03 02:24:16

Scimmia
Fellow
Registered: 2012-09-01
Posts: 13,729

Re: [SOLVED] Help clean-up personal mirror update script

What's the point of having that many mirrors in your mirrorlist, anyway?

Offline

#4 2022-03-03 07:37:06

Ferdinand
Member
From: Norway
Registered: 2020-01-02
Posts: 338

Re: [SOLVED] Help clean-up personal mirror update script

What was already said should cover it. Especially the scripting tutorial link!
To make it a little easier, perhaps, here's my two cents with respect to your script:

#! /bin/bash
{
    printf "**************************************************\n\n"
    printf "%s %s\n\n" "Backup created on" "$(date)"
    printf "**************************************************\n"
} >> /home/amghwk/.scripts/mirrorlist-backup
cat /etc/pacman.d/mirrorlist >> /home/amghwk/.scripts/mirrorlist-backup
reflector --country TH,SG,HK,VN,TW,JP,KR --sort age --latest 5 > /etc/pacman.d/mirrorlist

The change to the reflector line is just to choose the 5 mirrors with the lowest age (i.e. the most recently updated) out of all the mirrors that matches your country list. The assumption is that you don't care which country out of the ones you have selected is actually used, and so it would be better to select the most recently updated mirror. The number 5 is arbitrary; only the first responding mirror will be used.

Offline

#5 2022-03-03 10:11:06

bulletmark
Member
From: Brisbane, Australia
Registered: 2013-10-22
Posts: 713

Re: [SOLVED] Help clean-up personal mirror update script

@Ferdinard, shouldn't be hard-coding that home directory (in two places). Should use $HOME.

Offline

#6 2022-03-03 13:29:00

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,484
Website

Re: [SOLVED] Help clean-up personal mirror update script

And if you're going to use the { } set up  there, you may as well move the cat to the inside so the filename only needs to be in one place in the first place:

{
   printf ...
   printf ...
   printf ...
   cat /etc/pacman.d/mirrorlist
} >> $HOME/.scripts/mirrorlist-backup

reflector ...

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#7 2022-03-13 00:17:11

amghwk
Member
Registered: 2020-05-23
Posts: 43

Re: [SOLVED] Help clean-up personal mirror update script

Thank you for all the help.

I'll take your advices. Thanks.

Offline

#8 2022-03-13 00:20:00

amghwk
Member
Registered: 2020-05-23
Posts: 43

Re: [SOLVED] Help clean-up personal mirror update script

Scimmia wrote:

What's the point of having that many mirrors in your mirrorlist, anyway?

I've noticed sometimes the mirrors give not responsive errors. So I just have backups. And with these mirrors, communicating with the servers are very fast due to my location.

Offline

Board footer

Powered by FluxBB