Autor |
Sõnum |
layr
Uus kasutaja
Liitunud: 19.01.2011
Postitused: 6
Asukoht: Tartumaa
Distributsioon: Debian Wheezy
|
|
Leidsin netiavarustest scripti, mis äratab masina ette määratud aja pärast suspendist üles ning teeb, mida... tahad.
Oskab/viitsib keegi scripti modida, et suspendi aega ei defineeriks mitte tundide ja minutitega, vaid kellaajaga, nt 07:00, 15:25 vms.
Ei tahaks, et äratuskell öösel niisama jõude istub : )
EDIT: Valmisscript asub minu viimases postis. Edasised uuendused postitan sinna.
Kood: | #!/bin/sh
# Auto suspend and wake-up script
# ******** the computer on standby and automatically wakes it up after specified period
# How to use: download this script and place it on you computer.
# Call the script like this:
# suspend_for 1
# suspend_for 1 hour
# suspend_for 2 hours
# suspend_for 1 minute
# suspend_for 60 minutes
# suspend_for 1 hour 30 minutes
# suspend_for 2 hours 1 minute
# ehk teisisõnu dragi see scriptfile terminali ja kirjuta ajadefinitsioon nt "1 h 12 min"
# Original version courtesy of http://ubuntuforums.org/member.php?u=130449
# from thread http://ubuntuforums.org/showthread.php?t=938533&page=2
# Edited by Romke van der Meulen <redge.online@gmail.com>
# ------------------------------------------------------
# Argument check (kui argumente liiga palju v vähe, prindib terminali alloleva juhise)
MINARGS=1
MAXARGS=4
E_BADARGS=65
if [ $# -lt "$MINARGS" ] || [ $# -gt "$MAXARGS" ]; then
echo "Usage: `basename $0` [[number] hours/h] [[number] minutes/m]"
echo "E.G.: `basename $0` 2 hours"
echo "E.G.: `basename $0` 30 minutes"
echo "E.G.: `basename $0` 2 hours 30 minutes"
echo "E.G.: `basename $0` 2 h 30 m"
exit $E_BADARGS
fi
# ------------------------------------------------------
# Get root
sudo /bin/true
# Unload rtcwake if it's running, in case it was recalled after script finished.
SERVICE='rtcwake'
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "$SERVICE running, killing process..."
sudo killall rtcwake
else
echo "$SERVICE is not running, good to go."
fi
# Determine sleep interval
hours=0
minutes=0
multiply=0
total=0
# Check for first argument set, default hours (Estonian words added to definitions)
multiply=3600
if [ $# -gt 1 ]; then
if [ "$2" = "minutes" ] || [ "$2" = "minute" ] || [ "$2" = "m" ] || [ "$2" = "min" ] || [ "$2" = "minut" ] || [ "$2" = "minutit" ]; then
multiply=60
minutes=$1
else
multiply=3600
hours=$1
fi
fi
# Add time from first argument set
total=`expr $1 \* $multiply`
# Check for second argument set, default minutes (Estonian words added to definitions)
multiply=0
if [ $# -gt 2 ]; then
if [ "$4" = "hours" ] || [ "$4" = "hour" ] || [ "$4" = "h" ] || [ "$4" = "tund" ] || [ "$4" = "tundi" ] || [ "$4" = "t" ]; then
multiply=3600
hours=`expr $3 + $hours`
else
multiply=60
minutes=`expr $3 + $minutes`
fi
# Add time from second argument set
total=`echo "$total + ($3 * $multiply)" | bc`
fi
# Let user know what we're going to do
echo "Going to suspend for $hours hours $minutes minutes ($total seconds)"
echo "To cancel, press Ctrl+c within the next 10 seconds."
sleep 10
# Set wake up time,
sudo rtcwake -u -s $total -m on &
# give rtcwake some time to make its stuff
sleep 2
# then suspend
sudo pm-suspend
# Wake up with monitor disabled
#xset dpms force off
# and console cleared
#clear
# Any commands you want to launch after resume
# can be placed here
# Remember: sudo may have expired by now
echo "Goooooooood morning Vietnaaaaaam!"
# Set volume level (needs editing!)
# amixer -c 0 set PCM 90% unmute
# Open VLC (vlc + path to your audio/video file)
vlc '/home/Music/soundfile.mp3'
# Unload rtcwake if it's running, otherwise next time computer won't wake up from sleep
SERVICE='rtcwake'
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "$SERVICE running, killing process..."
sudo killall rtcwake
else
echo "$SERVICE is not running, no action taken."
fi
|
|
|
|
|
Viimati muutis layr 27.03.2012, 13:29; muudetud 2 korda
|
|
|
|
Kaar3l
Vana Pingviin
Vanus: 37
Liitunud: 07.05.2007
Postitused: 692
Asukoht: Plv
Distributsioon: Ubuntu
|
|
Pmst-lt peaks ju asi lihtne olema.
Uus tulevane kellaeg-praegune kellaaeg= saame aegade vahe(ehk mis aja pärast on vaja teha äratus)
Selle eelmise tulemus programmile ette anda ja peakski olema sinu tahetud süsteem olemas.
Ise ma seda muuta ei oska, pole skilli hetkel.
|
|
|
|
_________________ Hyva päiva!
|
|
|
|
andreas
Pingviini aktivist
Vanus: 30
Liitunud: 26.02.2008
Postitused: 112
Asukoht: Raasiku
Distributsioon: Mageia Cauldron
|
|
peaks äratama üles kell 7:00.
Kood: | #!/bin/sh
# Auto suspend and wake-up script
# ******** the computer on standby and automatically wakes it up after specified period
# How to use: download this script and place it on you computer.
# Call the script like this:
# suspend_for 1
# suspend_for 1 hour
# suspend_for 2 hours
# suspend_for 1 minute
# suspend_for 60 minutes
# suspend_for 1 hour 30 minutes
# suspend_for 2 hours 1 minute
# ehk teisisõnu dragi see scriptfile terminali ja kirjuta ajadefinitsioon nt "1 h 12 min"
# Original version courtesy of http://ubuntuforums.org/member.php?u=130449
# from thread http://ubuntuforums.org/showthread.php?t=938533&page=2
# Edited by Romke van der Meulen <redge.online@gmail.com>
# ------------------------------------------------------
# Argument check (kui argumente liiga palju v vähe, prindib terminali alloleva juhise)
MINARGS=1
MAXARGS=4
E_BADARGS=65
if [ $# -lt "$MINARGS" ] || [ $# -gt "$MAXARGS" ]; then
echo "Usage: `basename $0` [[number] hours/h] [[number] minutes/m]"
echo "E.G.: `basename $0` 2 hours"
echo "E.G.: `basename $0` 30 minutes"
echo "E.G.: `basename $0` 2 hours 30 minutes"
echo "E.G.: `basename $0` 2 h 30 m"
exit $E_BADARGS
fi
# ------------------------------------------------------
# Get root
sudo /bin/true
# Unload rtcwake if it's running, in case it was recalled after script finished.
SERVICE='rtcwake'
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "$SERVICE running, killing process..."
sudo killall rtcwake
else
echo "$SERVICE is not running, good to go."
fi
total=$[`date -d $1 +%s`-`date +%s`]
if [ $total -le 0 ]; then total=$[$total+86400]; fi
# Let user know what we're going to do
echo "Going to suspend for $hours hours $minutes minutes ($total seconds)"
echo "To cancel, press Ctrl+c within the next 10 seconds."
sleep 10
# Set wake up time,
sudo rtcwake -u -s $total -m on &
# give rtcwake some time to make its stuff
sleep 2
# then suspend
sudo pm-suspend
# Wake up with monitor disabled
#xset dpms force off
# and console cleared
#clear
# Any commands you want to launch after resume
# can be placed here
# Remember: sudo may have expired by now
echo "Goooooooood morning Vietnaaaaaam!"
# Set volume level (needs editing!)
# amixer -c 0 set PCM 90% unmute
# Open VLC (vlc + path to your audio/video file)
vlc '/home/Music/soundfile.mp3'
# Unload rtcwake if it's running, otherwise next time computer won't wake up from sleep
SERVICE='rtcwake'
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "$SERVICE running, killing process..."
sudo killall rtcwake
else
echo "$SERVICE is not running, no action taken."
fi
|
|
|
|
|
|
|
|
|
layr
Uus kasutaja
Liitunud: 19.01.2011
Postitused: 6
Asukoht: Tartumaa
Distributsioon: Debian Wheezy
|
|
Nüüd töötab heli unmute ja tugevuse reguleerimine (olenevalt süsteemi confist võib teil muidugi alsamixeri käsud erineda)
Edit (27.03.12):
Täiendatud dokumentatsioon, lisatud äratuse edasi lükkamise funktsioon.
Kood: | #!/bin/bash
# Auto suspend and wake-up script. It's intended to act as an alarm-clock.
#
# Switches the computer on standby (after pre-defined time) and automatically wakes it up and executes commands at specified time or
# executes commands after given sleep period.
#
# Written by Romke van der Meulen <redge.online at gmail>
# Edited by Laur Aliste <laur.aliste at gmail>
#
# -----------------------------------------------------
# If you want the script to work without typing any passwords, you have to edit sudoers file:
# sudo visudo
# go to the last line and enter this line (without the '# ' at the beginning!) and save:
# username ALL=NOPASSWD: /usr/sbin/rtcwake
#
# !!! This step is only needed if you're going to use (long) pre-suspend sleep periods; if so, sudo might
# expire before 'sudo rtcwake' command is executed and system won't suspend !!!
# -----------------------------------------------------
##### USAGE #####
#
# 3 usage methods:
# 1. Suspending to RAM:
# Example: suspend_script 930 15 - suspends system after 15 min and wakes up at 9:30
# suspend_script 1845 10 - suspends system after 10 min and wakes up at 18:45
# suspend_script 0325 2 - suspends system after 2 min and wakes up at 03:25
# suspend_script 515 - If the second argument (pre-suspend sleep time) is missing as it is in this example,
# the default value is 10 sec, so the system suspends after 10 sec
# and wakes up at 05:15
# 2. Sleeping until predefined time:
# Example: suspend_script 930 sleep - executes pre-defined commands at 9:30
#
# 3. Sleeping for given time:
# Example: suspend_script sleep 31 - executes pre-defined commands after sleeping for 31 minutes
# suspend_script sleep - If the second argument (sleep time) is missing as it is in this example,
# the default value is 10 min, so the system executes pre-defined commands
# after sleeping for 10 minutes
#
#
# - You can place this file (suspend_script) into /usr/local/bin. When you want to use the script, open terminal
# and type "suspend_script TIMEVALUE SLEEPVALUE" or
# - simply drag the scriptfile (located anywhere) into terminal window and add those two values to the end of command line.
#
# Don't forget to make this file executable!
# ------------------------------------------------------
# Default values; do not change:
standalone_sleep=0
suspend=1
# Argument check:
if [[ $# > 2 ]]; then
echo "==============================================================================="
echo " Error: too many arguments;"
echo " only wake-up time and/or sleep arguments are accepted"
echo "==============================================================================="; exit 1
fi
if [[ $# < 1 ]]; then
echo "====================================================="
echo " Wake-up time (HHMM) or \"sleep\" needed"
echo "====================================================="; exit 1
fi
if [[ "$1" == "sleep" ]] ; then
standalone_sleep=1
suspend=0
if ! [[ -z $2 ]]; then
if ! [[ "$2" =~ ^[0-9]+$ ]] ; then
echo "========================================================================="
echo " Error: sleep value (MM) has to be numerical."
echo " eg. 10; 200; 5"
echo "========================================================================="; exit 1
fi
fi
elif ! [[ "$1" =~ ^[0-9]+$ ]]; then
echo "=============================================================="
echo " Error: first argument has to be either numerical (HHMM)"
echo " eg. 1000; 900; 1830; or \"sleep\""
echo "=============================================================="; exit 1
elif ! [[ -z $2 ]]; then
if [[ "$2" == "sleep" ]] ; then
suspend=0
elif ! [[ "$2" =~ ^[0-9]+$ ]] ; then
echo "========================================================================="
echo " Error: second argument has to be either numerical (MM)"
echo " eg. 10; 200; 5; or \"sleep\""
echo "========================================================================="; exit 1
fi
fi
# Check whether specified time is today or tomorrow and define suspend period:
if [[ $standalone_sleep == 0 ]]; then
TARGET1=$((`date +%s -d "$1"`))
NOW=$((`date +%s`))
if [ $TARGET1 -lt $NOW ]; then
TARGET1=$((`date +%s -d "$1"` + 24*60*60))
fi
TARGET=$(($TARGET1-$NOW))
fi
# Define hours/mins/sec until wake-up:
hours=$(($TARGET/3600))
minutes=$(( ($TARGET-($hours*3600))/60 ))
seconds=$(( $TARGET-(($hours*3600)+($minutes*60)) ))
# Check whether entered wake-up time makes any sense:
if [[ "$1" =~ ^[0-9]+$ ]] ; then
if (( $hours < 0 )); then
echo "======================================================"
echo " Error: please re-check the wake-up time"
echo "======================================================"; exit 1
fi
fi
# Decide whether to sleep or suspend; define pre-suspend sleep durance if necessary:
if [[ $suspend == 1 ]]; then
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
#-------------------------------#-# SUSPEND SCRIPT #-#--------------------------------#
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
killall rtcwake > /dev/null 2>&1
if [[ $2 > 0 ]];then
sleep_value=$(( $2*60 ))
else
sleep_value=10
fi
# Print countdown feedback:
while [ $sleep_value -gt 0 ]; do
clear
# Let user know what we're going to do
echo "Going to suspend for $hours h $minutes min"
let sleep_value=$sleep_value-1
hours2=$(( $sleep_value/3600 ))
minutes2=$(( ($sleep_value-$hours2*3600)/60 ))
seconds2=$(( $sleep_value-($hours2*3600+$minutes2*60) ))
echo "----------------------------------------------------------"
if [[ $hours2 > 0 ]] ;then
echo "To cancel, press Ctrl+c within the next $hours2 h $minutes2 min $seconds2 sec"
elif [[ $minutes2 > 0 ]] ;then
echo "To cancel, press Ctrl+c within the next $minutes2 min $seconds2 sec"
else
echo "To cancel, press Ctrl+c within the next $seconds2 sec"
fi
sleep 1
done
#################################################################################################
#################################################################################################
# Between these double octothorpe (#) lines go optional commands
# which are to be executed BEFORE suspension:
#------------------------------------------------------------------------------------------------
# Kill conky:
#pkill -9 -f conky > /dev/null 2>&1
#################################################################################################
#################################################################################################
# Feedback again:
echo "Suspending..."
sleep 1
# Set RTC wakeup time and suspend to RAM:
sudo rtcwake -m mem -s $TARGET
# Buffer time...
sleep 2
#################################################################################################
#################################################################################################
# Between these double octothorpe (#) lines go optional commands
# which are to be executed AFTER suspension:
#------------------------------------------------------------------------------------------------
# Wake up with monitor disabled:
# xset dpms force off
# Clear the terminal window:
clear
# Set volume level and (just in case) unmute system:
amixer -c 0 set Master 80% unmute > /dev/null 2>&1
amixer -c 0 set PCM 80% unmute > /dev/null 2>&1
# Start conky:
#conky -c /home/laur/.conkyrc > /dev/null 2>&1
#conky -c /home/laur/.conkyrc_banshee > /dev/null 2>&1
echo "
Good morning
"
# Start ncmpcpp:
ncmpcpp play > /dev/null 2>&1
# Postpone? :
echo -n "Want to sleep some more? (y/n) "
read postpone
if [[ "$postpone" == "y" ]]; then
while [[ "$postpone" == "y" ]]; do
ncmpcpp pause > /dev/null 2>&1
echo -n "Enter time in minutes (leave blank for 10min): "
read sleep_value
if ! [[ -z $sleep_value ]]; then
if ! [[ "$sleep_value" =~ ^[0-9]+$ ]] ; then
echo "========================================================================="
echo " Error: sleep time (MM) has to be numerical."
echo " eg. 10; 20; 5"
echo "========================================================================="; exit 1
fi
fi
if [[ $sleep_value > 0 ]];then
sleep_value=$(( $sleep_value*60 ))
else
sleep_value=600
fi
# Define hours/mins/sec until wake-up:
hours=$(( $sleep_value/3600 ))
minutes=$(( ($sleep_value-$hours*3600)/60 ))
seconds=$(( $sleep_value-($hours*3600+$minutes*60) ))
while [ $sleep_value -gt 0 ]; do
clear
# Let user know what we're going to do
if [[ $hours > 0 ]] ;then
echo "Going to sleep for $hours h $minutes min"
else
echo "Going to sleep for $minutes min"
fi
let sleep_value=$sleep_value-1
hours2=$(( $sleep_value/3600 ))
minutes2=$(( ($sleep_value-$hours2*3600)/60 ))
seconds2=$(( $sleep_value-($hours2*3600+$minutes2*60) ))
echo "----------------------------------------------------------"
if [[ $hours2 > 0 ]] ;then
echo "Waking up in... $hours2 h $minutes2 min $seconds2 sec"
elif [[ $minutes2 > 0 ]] ;then
echo "Waking up in... $minutes2 min $seconds2 sec"
else
echo "Waking up in... $seconds2 sec"
fi
sleep 1
done
amixer -c 0 set Master 80% unmute > /dev/null 2>&1
amixer -c 0 set PCM 80% unmute > /dev/null 2>&1
ncmpcpp play > /dev/null 2>&1
echo -n "Want to sleep some more? (y/n) "
read postpone
done
fi
#################################################################################################
#################################################################################################
# Unload rtcwake if it's running, otherwise next time computer won't wake up from sleep:
killall rtcwake > /dev/null 2>&1
exit 1
fi
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
#-------------------------------#-# SLEEP SCRIPT #-#--------------------------------#
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
#################################################################################################
#################################################################################################
# Between these double octothorpe (#) lines go optional commands
# which are to be executed BEFORE system sleep:
#------------------------------------------------------------------------------------------------
#################################################################################################
#################################################################################################
if [[ "$standalone_sleep" == "1" ]]; then
if [[ $2 > 0 ]];then
sleep_value=$(( $2*60 ))
else
sleep_value=600
fi
# Define hours/mins/sec until wake-up:
hours=$(( $sleep_value/3600 ))
minutes=$(( ($sleep_value-$hours*3600)/60 ))
seconds=$(( $sleep_value-($hours*3600+$minutes*60) ))
while [ $sleep_value -gt 0 ]; do
clear
# Let user know what we're going to do
if [[ $hours > 0 ]] ;then
echo "Going to sleep for $hours h $minutes min"
else
echo "Going to sleep for $minutes min"
fi
let sleep_value=$sleep_value-1
hours2=$(( $sleep_value/3600 ))
minutes2=$(( ($sleep_value-$hours2*3600)/60 ))
seconds2=$(( $sleep_value-($hours2*3600+$minutes2*60) ))
echo "----------------------------------------------------------"
if [[ $hours2 > 0 ]] ;then
echo "Waking up in... $hours2 h $minutes2 min $seconds2 sec"
elif [[ $minutes2 > 0 ]] ;then
echo "Waking up in... $minutes2 min $seconds2 sec"
else
echo "Waking up in... $seconds2 sec"
fi
sleep 1
done
else
sleep_value=$TARGET
while [ $sleep_value -gt 0 ]; do
clear
# Let user know what we're going to do
if [[ $hours > 0 ]] ;then
echo "Going to sleep for $hours h $minutes min $seconds s"
elif [[ $minutes > 0 ]] ;then
echo "Going to sleep for $minutes min $seconds s"
else
echo "Going to sleep for $seconds s"
fi
let sleep_value=$sleep_value-1
hours2=$(( $sleep_value/3600 ))
minutes2=$(( ($sleep_value-$hours2*3600)/60 ))
seconds2=$(( $sleep_value-($hours2*3600+$minutes2*60) ))
echo "----------------------------------------------------------"
if [[ $hours2 > 0 ]] ;then
echo "Waking up in... $hours2 h $minutes2 min $seconds2 sec"
elif [[ $minutes2 > 0 ]] ;then
echo "Waking up in... $minutes2 min $seconds2 sec"
else
echo "Waking up in... $seconds2 sec"
fi
sleep 1
done
fi
#################################################################################################
#################################################################################################
# Between these double octothorpe (#) lines go optional commands
# which are to be executed AFTER system sleep:
#------------------------------------------------------------------------------------------------
clear
# Set volume level and (just in case) unmute system:
amixer -c 0 set Master 80% unmute > /dev/null 2>&1
amixer -c 0 set PCM 80% unmute > /dev/null 2>&1
# Start conky:
#conky -c /home/laur/.conkyrc > /dev/null 2>&1
#conky -c /home/laur/.conkyrc_banshee > /dev/null 2>&1
echo "
Wakey-wakey
"
#Start ncmpcpp:
ncmpcpp play > /dev/null 2>&1
# Postpone? :
echo -n "Want to sleep some more? (y/n) "
read postpone
if [[ "$postpone" == "y" ]]; then
while [[ "$postpone" == "y" ]]; do
ncmpcpp pause > /dev/null 2>&1
echo -n "Enter time in minutes (leave blank for 10min): "
read sleep_value
if ! [[ -z $sleep_value ]]; then
if ! [[ "$sleep_value" =~ ^[0-9]+$ ]] ; then
echo "========================================================================="
echo " Error: sleep time (MM) has to be numerical."
echo " eg. 10; 20; 5"
echo "========================================================================="; exit 1
fi
fi
if [[ $sleep_value > 0 ]];then
sleep_value=$(( $sleep_value*60 ))
else
sleep_value=600
fi
# Define hours/mins/sec until wake-up:
hours=$(( $sleep_value/3600 ))
minutes=$(( ($sleep_value-$hours*3600)/60 ))
seconds=$(( $sleep_value-($hours*3600+$minutes*60) ))
while [ $sleep_value -gt 0 ]; do
clear
# Let user know what we're going to do
if [[ $hours > 0 ]] ;then
echo "Going to sleep for $hours h $minutes min"
else
echo "Going to sleep for $minutes min"
fi
let sleep_value=$sleep_value-1
hours2=$(( $sleep_value/3600 ))
minutes2=$(( ($sleep_value-$hours2*3600)/60 ))
seconds2=$(( $sleep_value-($hours2*3600+$minutes2*60) ))
echo "----------------------------------------------------------"
if [[ $hours2 > 0 ]] ;then
echo "Waking up in... $hours2 h $minutes2 min $seconds2 sec"
elif [[ $minutes2 > 0 ]] ;then
echo "Waking up in... $minutes2 min $seconds2 sec"
else
echo "Waking up in... $seconds2 sec"
fi
sleep 1
done
amixer -c 0 set Master 80% unmute > /dev/null 2>&1
amixer -c 0 set PCM 80% unmute > /dev/null 2>&1
ncmpcpp play > /dev/null 2>&1
echo -n "Want to sleep some more? (y/n) "
read postpone
done
fi
#################################################################################################
#################################################################################################
exit 1 |
|
|
|
|
|
|
|
|
|
|