Meniu

Obtineti ora de rasarit si apus a soarelui pentru orice locatie din linia de comanda Linux

Sunrise & Sunset - script simplu este pentru ora de rasarit si apus a soarelui pentru orice locatie din linia de comanda Linux.

#!/bin/bash

# First obtain a location code from: https://weather.codes/search/

# Insert your location. For example LOXX0001 is a location code for Bratislava, Slovakia location="LOXX0001"

# Obtain sunrise and sunset raw data from weather.com sun_times=$( lynx --dump https://weather.com/weather/today/l/$location | grep "\* Sun" | sed "s/[[:alpha:]]//g;s/*//" ) # Extract sunrise and sunset times and convert to 24 hour format sunrise=$(date --date="`echo $sun_times | awk '{ print $1}'` AM" +%R) sunset=$(date --date="`echo $sun_times | awk '{ print $2}'` PM" +%R)

# Use $sunrise and $sunset variables to fit your needs. Example: echo "Sunrise for location $location: $sunrise" echo "Sunset for location $location: $sunset"

Alternativ, puteti clona, ??de asemenea, cea mai recenta versiune de la github:

$ Git clona https://github.com/linuxconfig/Sunrise-Sunset-Shell-Script.git

Obtineti codul de locatie https://weather.codes/search/si atribuiti - l variabila in timp ce inlocuitil. Salvati fisierul si executatil:

$ Chmod + x sunrise-sunset.sh

Asigurati - va ca lynx este disponibil pe sistemul Linux si executati:

UBUNTU/DEBIAN
# apt install lynx
CENTOS/REDHAT
# yum install lynx

Apoi rulati script-ul:

$ ./sunrise-sunset.sh 
Sunrise for location LOXX0001: 06:47
Sunset for location LOXX0001: 18:34

FlorinM

Utilizator Linux - Solus OS, pasionat de calatorii.
  • | 2708 articole

Nici un comentariu inca. Fii primul!
  • powered by Verysign