Skip to main content

Thread: Script root at startup


hi.

wrote script in order shutdown computer while watching movie. if sleeping, script has shutdown computer or else have press key prove still awake.

run script automatically @ startup.
script has run root (the owner root) (since there commands kill or shutdown).
may have been several solutions:
avoid change fact commands such "kill" or "shutdown" can run non-administrator user (cf viduso) : script has launch root user don't want tape passwword @ startup.

saw solution consists in make/change startup script such /etc/local.rc (i tried putting "xterm -e my_script.sh" @ nothing changed @ startup.
have run script in terminal (since have interact script few minutes after startup).

give source code:

code:
#!/bin/bash #shut computer while watching movie mplayer or vlc #version 10/1012  if test `id -u` != "0"; 	echo "you not bigboss" 	exit 1 fi  if [ $# -eq 0 ];  	limit=20 else 	limit="$1" fi  echo "########################################################################" echo "# zoobie's gonna shutdown in $limit " echo "minutes (subject vlc or mp) #" echo "########################################################################"  endormi=0  while [ "$endormi" -eq 0 ]  	sleep "$limit"m  	pid=`ps -e | grep "mplayer\|vlc" | awk '{print $1}'`  	if [ ! -z "$pid" ] 	then 		sudo kill -stop "$pid"  		#kill -stop "$pid"  		app=`wmctrl -l | grep "terminal" | awk '{print $1}'` 		wmctrl -i -a "$app" 	fi  	echo "are sleeping ?" 	read -n1 -t 17 endormi	  	if [ ! -z "$endormi" ] 	then 		endormi=0 		if [ ! -z "$pid" ] 		then 			app=`wmctrl -l | grep "mplayer\|vlc" | awk '{print $1}'` 			wmctrl -i -a "$app" 			kill -cont "$pid" 			echo "keep watching" 			continue 		fi 	else 		endormi=1 	fi  done  shutdown -p  echo "				sleep     tight" exit(0)

suggestions ?

you on right track, there's no need use xterm run script rc.local. invoke script, on line before existing "exit 0" line.

note run during boot sequence, long before has logged in. runs in console, it's 1 has no keyboard or monitor attached, instructions have coded script or passed on command line in rc.local. won't able interact script @ point, , possibly never. file , command references, also, have absolute paths, not relative, since path environment variable not yet set , in event different root , normal users. , messages won't go anywhere; they'll waste few cycles of cpu time.

if run automatically @ startup, shut down machine after 20 minutes unless tell you're awake, no matter whether you're watching movie or trying read e-mail. perhaps desktop launcher icon less irritating way start it, , allow messages , interaction -- it's system can set way want!

edit: incidentally, can edit /etc/sudoers file, using visudo, allow script, nothing else, run via sudo without requiring password. let launch icon without having input password.


Forum The Ubuntu Forum Community Ubuntu Official Flavours Support General Help [ubuntu] Script root at startup


Ubuntu

Comments

Popular posts from this blog

Could not place because the source rectangle is empty

Thread: Using smartcard reader with vpnc

Adobe Font Folio 7.0 or just 7?