Site Tools


linux:raspberry:raspbian:scripts:clock

This is an old revision of the document!


Date and Time Script

This script can be used to change the date and time if your Raspberry is not connected to a network or timeserver. To do this, you need to enter the current date and time in the correct format. It will refresh after some seconds.

#!/bin/sh
 
#Lunetikk | 03.04.2014 | Change date and time
 
 
read -p "Insert date like YYYY-MM-DD:" DATE
read -p "Insert time like HH:MM:SS:" TIME
 
sudo date -s "$DATE $TIME" 
sudo fake-hwclock

scriptstarter.sh
    #!/bin/bash
 
    #var SERVICE starts the script with nohup and & in the background. the shell can still be used even with the script running.
    SERVICE=nohup /home/script/script.sh &
 
    #var SERVICENAME is without nohup and & so it will not be shown in the scriptname
    SERVICENAME=/home/script/script.sh
 
    #if the running script is started with start it will echo "was started", stop = stop, restart = stop,start, anything else will return what you can do.
    case "$1" in
    start)
    	$SERVICE
    	[ $? -eq 0 ] && echo "$SERVICENAME was started"
    ;;
    stop)
    	pkill -f $SERVICENAME
    	[ $? -eq 0 ] && echo "$SERVICENAME was stopped"
    ;;
    restart) 
    	$0 stop
    	$0 start
    ;;
    *)
    	echo "Usage: $0 (start|stop|restart)"
    ;;
    esac



linux/raspberry/raspbian/scripts/clock.1513676827.txt.gz · Last modified: 2017/12/19 10:47 (external edit)