CrunchBang Linux Pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

CrunchBang Linux Pastebin

Difference between
modified post 742 by jmbarnes on Thu 19th Aug 03:48 and
original post 740 by jmbarnes on Wed 18th Aug 22:38
Show old version | new version | both versions

    
11
#!/bin/bash
22
#This is a script that acts a a sleep timer or basic alarm.
33
#It is written for crunchbang linux installs--but should move
44
#easily to most any linux distributions.
55
#For most users you'll want to edit the series of commands
66
#below to use whatever programs/utilities you favor
88
######DEFAULT COMMANDS#####
1010
#The path to the alarm noise (e.g. a beep, song, etc.)
1111
NOISE=~/music/WhatIGot.m4a
1212
#Program for playing the alarm
13-
ALARM="cvlc --repeat $NOISE && echo "Press CTRL-C to exit""
13+
ALARM="vlc --repeat $NOISE"
1414
#Screen locking command
1515
SCREENLOCK="xscreensaver-command -lock"
1616
#The suspending command
1717
SUSPEND="pm-suspend"
1818
#The hibernation command
1919
HIBERNATE="pm-hibernate"
2020
#Command or series of commands for shutting down
2121
SHUTDOWN="gdm-control --shutdown && openbox --exit"
2222
#Common use scripts (1st a backup script) You can
2323
#add more here and then duplicate lines 147-9, and edit accordingly.
2424
BACKUPSCRIPT="/home/jake/bin/remotebackup.sh"
2727
########SCRIPT GENERAL INPUTS#####
2828
#Select action to take
2929
PS3="Choose:"
3030
echo ""
3131
echo "What action would you like to take at the end?"
3232
select act in "suspend" "hibernate" "lock screen" "shutdown" "play alarm"
3333
do
3434
	break
3535
done
3737
#################################
3838
#Translating the "acts" to  proper commands
3939
#################################
4040
if [ "$act" = "suspend" ]; then
4141
	actcommand=$SUSPEND
4242
fi
4343
if [ "$act" = "hibernate" ]; then
4444
	actcommand=$HIBERNATE
4545
fi
4646
if [ "$act" = "lock screen" ]; then
4747
	actcommand=$SCREENLOCK
4848
fi
4949
if [ "$act" = "shutdown" ]; then
5050
	actcommand=$SHUTDOWN
5151
fi
5252
if [ "$act" = "play alarm" ]; then
5353
	actcommand=$ALARM
5454
fi
5656
##Asking for passwords for those commands which need root privileges
5757
if [ "$actcommand" = "$SUSPEND" ] || [ "$actcommand" = "$HIBERNATE" ]; then
5858
	echo "Selected action requires root privileges."
5959
	stty_orig=`stty -g`
6060
	stty -echo
6161
	read -p "Enter sudo password:" pass
6262
	stty $stty_orig
6363
fi
6565
#Select when you would like to do it
6666
PS3="Choose: "
6767
echo ""
6868
echo "When would you like to do it?"
6969
select when in "after time" "after task" "whichever is later"
7070
do
7171
	break
7272
done
7373
echo ""
7575
#Show the current alarm path
7676
if [ "$act" = "play alarm" ]; then
7777
	echo "Current path of alarm is set to $NOISE"
7878
	echo ""
7979
fi
8181
#For 'whens' that require a time input
8282
if [ "$when" = "after time" ] || [ "$when" = "whichever is later" ]; then
8383
	read -p "How long of a delay (in minutes): " minutes
8484
	echo ""
8585
	sectime=`date +%s`
8686
	secoff=$(($sectime+($minutes*60)))
8787
	dateoff=`date --date=@$secoff`
8888
fi
9090
########################
9191
#####The  After Time Routine
9292
########################
9393
if [ "$when" = "after time" ]; then
9494
	#The Main Timer
9595
	elapsedtime=1
9696
	echo ""
9797
	echo ""
9898
	echo "Computer will $act at $dateoff."
9999
	echo -n "Minutes left..."
100100
	echo -n "$minutes..."
101101
	while [ $elapsedtime -lt $minutes ]
102102
		do
103103
		    sleep 1m
104104
		    echo -n "$(($minutes-$elapsedtime)).."
105105
    		elapsedtime=$(($elapsedtime+1))
106106
		done
107107
	#The last 60 seconds....
108108
	echo ""
109109
	echo ""
110110
	if [ $minutes -gt 0 ]; then
111111
		echo "Will $act in (seconds)..."
112112
		lastsixty=1
113113
		while [ $lastsixty -le 60 ]
114114
			do
115115
	    		sleep 1s
116116
	   			 echo -n "$((60-$lastsixty))..."
117117
	    		lastsixty=$(($lastsixty+1))
118118
			done
119119
	fi
120120
	#The Action
121121
	if [ "$actcommand" = "$SUSPEND" ] || [ "$actcommand" = "$HIBERNATE" ]; then
122122
		echo "$pass" | sudo -S $actcommand
123123
		exit 0
124124
		else
125125
			$actcommand
126126
			exit 0
127127
	fi
128128
fi
130130
#####################
131131
#Inputing the task to follow
132132
#####################
133133
if [ "$when" = "after task" ] || [ "$when"  = "whichever is later" ]; then
134134
	PS3="Choose: "
135135
	echo ""
136136
	echo "Which task do you want to follow?"
137137
	select task in "Already running task (pid)" "A new task" "Backup script"
138138
	do
139139
		break
140140
	done
141141
	if [ "$task" = "Already running task (pid)" ]; then
142142
		read -p "Enter pid of task" taskpid
143143
	fi
144144
	if [ "$task" = "A new task" ]; then
145145
		taskpid=0
146146
		read -p "Enter (terminal) command to run: " taskcommand
147147
	fi
148148
	if [ "$task" = "Backup script" ]; then
149149
		taskpid=0
150150
		taskcommand=$BACKUPSCRIPT
151151
	fi
152152
fi
154154
########################
155155
#####The After Task Routine
156156
########################
157157
if [ "$when" = "after task" ]; then
158158
	if [ "$taskpid" = "0" ]; then
159159
		terminator --command="$taskcommand" &
160160
		clear
161161
		taskpid=$!
162162
	fi
163163
	RUNNING=1
164164
	while [ $RUNNING -ge 1 ]
165165
		do
166166
			echo "Task still running"
167167
			sleep 5s
168168
			RUNNING=`ps $taskpid | grep -c $taskpid`
169169
		done
170170
	echo "Task complete...will now $act ."
171171
		if [ "$actcommand" = "$SUSPEND" ] || [ "$actcommand" = "$HIBERNATE" ]; then
172172
		echo "$pass" | sudo -S $actcommand
173173
		exit 0
174174
		else
175175
			$actcommand
176176
			exit 0
177177
		fi
178178
fi
180180
###############################
181181
#####The Whichever Is Later Routine
182182
###############################
183183
if [ "$when"  = "whichever is later" ]; then
184184
	if [ "$taskpid" = "0" ]; then
185185
		terminator --command="$taskcommand" &
186186
		taskpid=$!
187187
	fi
188188
	RUNNING=1
189189
	while [ $RUNNING -ge 1 ]
190190
		do
191191
			echo "Task still running..."
192192
			sleep 5s
193193
			RUNNING=`ps $taskpid | grep -c $taskpid`
194194
			clear
195195
		done
196196
	echo ""
197197
	echo "Task complete...comparing with set $dateoff ."
198198
	postbackuptime=`date +%s`
199199
	if [ $secoff -gt $postbackuptime ]; then
200200
		timedifference=$(($secoff-($postbackuptime)))
201201
		echo ""
202202
		echo "Sleeping for $timedifference seconds"
203203
		sleep $timedifference
204204
	fi
205205
	if [ "$actcommand" = "$SUSPEND" ] || [ "$actcommand" = "$HIBERNATE" ]; then
206206
		echo "$pass" | sudo -S $actcommand
207207
		exit 0
208208
		else
209209
			$actcommand
210210
			exit 0
211211
	fi
212212
fi
214214
exit
215215
#end

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me