You are not logged in.
Hi, I have the following script to update the mirrors:
#! /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
First, why are you running reflector half a dozen times? Just use one call:
reflector -c th,sg,hk,vn,tw,jp,kr --sort countryBut 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/mirrorlistYou 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
What's the point of having that many mirrors in your mirrorlist, anyway?
Offline
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/mirrorlistThe 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
@Ferdinard, shouldn't be hard-coding that home directory (in two places). Should use $HOME.
Online
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
Thank you for all the help.
I'll take your advices. Thanks.
Offline
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