Hi,
Ich möchte ein eigenes Shutdown-Script schreiben, um ein Backup zu integrieren.
Unter Slackware habe ich das als Sudo mit "shutdown -h now" realisiert...
Geht das nicht auch einfacher? Also ohne entsprechenden Eintrag via sudo?
viele Grüße
tom
			
			
													mit welchem Befehl Salix von der Konsole herunterfahren [gelöst]
mit welchem Befehl Salix von der Konsole herunterfahren [gelöst]
					Last edited by OsunSeyi on 14. Mar 2018, 12:52, edited 1 time in total.
									
			
						
										
						Re: mit welchem Befehl Salix von der Konsole herunterfahren
Ich hab tatsächlich eine andere Möglichkeit gefunden.
Da /usr/bin/wm-logout ConsoleKit verwendet, ergab Suche im Netz den Befehl
Fährt das System ohne weitere Rechte oder Nachfrage ac hoc herunter.
Erschien mir subjektiv aber schneller als via Button im wm-logout, ich hoffe, obiger Befehl beendet alle Prozesse sauber.
Das folgende ist mit GtkDialog und meinen etwas mageren Kentnissen zusammengebastelt.
Es erlaubt logout, reboot und shutdown mit (oder ohne) vorangehendem Backup:
			
			
									
						
										
						Da /usr/bin/wm-logout ConsoleKit verwendet, ergab Suche im Netz den Befehl
Code: Select all
dbus-send --system --print-reply --dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.StopErschien mir subjektiv aber schneller als via Button im wm-logout, ich hoffe, obiger Befehl beendet alle Prozesse sauber.
Das folgende ist mit GtkDialog und meinen etwas mageren Kentnissen zusammengebastelt.
Es erlaubt logout, reboot und shutdown mit (oder ohne) vorangehendem Backup:
Code: Select all
#!/bin/sh
export MAIN_DIALOG='
<window title="SYSHALT"><vbox>
<hbox>
	<checkbox active="true">
		<label>Backup</label>
		<variable>BACKUP</variable>
		<action>echo $BACKUP</action>
	</checkbox>
 
</hbox><hbox>
	<button>
		<label>Logout</label>
		<input file icon="application-exit"></input>
		<action>echo "logout"</action>
		<action type="exit">exit</action>
	</button><button>
		<label>Reboot</label>
		<input file icon="view-refresh"></input>
		<action>echo "reboot"</action>
		<action type="exit">exit</action>
	</button><button>
		<label>Shutdown</label>
		<input file icon="gnome-shutdown"></input>
		<action>echo "shutdown"</action>
		<action type="exit">exit</action>
	</button>
	<button cancel></button>
</hbox>
</vbox></window>'
	RESULT=`gtkdialog --program=MAIN_DIALOG  --geometry +35+620`
# EXIT:
	if   [ -n "$(echo $RESULT | grep Cancel)"   ]	; then exit 0 ; fi
# BACKUP:
	BACKUP=`echo $RESULT | grep 'BACKUP="true"'`
	if [ -n "$BACKUP" ] ; then
		echo 'backup' # rsync....
	fi
# LOGOUT / REBOOT / SHUTDOWN:
	if   [ -n "$(echo $RESULT | grep logout)"   ]	; then
		xlogout
	elif [ -n "$(echo $RESULT | grep reboot)"   ]	; then
		dbus-send --system --print-reply --dest=org.freedesktop.ConsoleKit       \
		/org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart
	elif [ -n "$(echo $RESULT | grep shutdown)" ] 	; then
		dbus-send --system --print-reply --dest=org.freedesktop.ConsoleKit 	 \
		/org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop
	fi
exit 0
Re: mit welchem Befehl Salix von der Konsole herunterfahren
I'm going to reply in English because my German is getting rusty ...
Yes, I think dbus and ConsoleKit is the better way to go. Glancing at your script, I wonder if it allows time for rsync to complete before the shutdown?
What I do myself is use the scripts bundled with Salix's ratpoison package:
			
			
									
						
										
						Yes, I think dbus and ConsoleKit is the better way to go. Glancing at your script, I wonder if it allows time for rsync to complete before the shutdown?
What I do myself is use the scripts bundled with Salix's ratpoison package:
Code: Select all
mimosa[~]$ cat /usr/bin/rpshutdown
#!/usr/bin/env python
import dbus
bus = dbus.SystemBus()
shut = bus.get_object('org.freedesktop.ConsoleKit','/org/freedesktop/ConsoleKit/Manager')
shutr = dbus.Interface(shut, 'org.freedesktop.ConsoleKit.Manager')
shutr.Stop()
mimosa[~]$ cat /usr/bin/rpreboot
#!/usr/bin/env python
import dbus
bus = dbus.SystemBus()
shut = bus.get_object('org.freedesktop.ConsoleKit','/org/freedesktop/ConsoleKit/Manager')
shutr = dbus.Interface(shut, 'org.freedesktop.ConsoleKit.Manager')
shutr.Restart()
Re: mit welchem Befehl Salix von der Konsole herunterfahren
Yes, the script is in fact waiting till rsync is ready, (good luck)
but woudn't it be better do do:
rsync opt.. &&
??
I'm scripting since years, but not on a high level. Everything's very simple.
But I have the experience, that rsync might cause awful problems if it's not correct used.
For exemple, if you use $HOME in the path and start it later not from a terminal but with a button...
Of cause it's ok to try --dry-run before it's getting serious...
			
			
									
						
										
						but woudn't it be better do do:
rsync opt.. &&
??
I'm scripting since years, but not on a high level. Everything's very simple.
But I have the experience, that rsync might cause awful problems if it's not correct used.
For exemple, if you use $HOME in the path and start it later not from a terminal but with a button...
Of cause it's ok to try --dry-run before it's getting serious...
Code: Select all
  DRY='--dry-run'
#  DRY=' '
   RSYNC_DAT='rsync -a -v -u '$DRY' --delete --exclude-from=.....'
   RSYNC_HOME='rsync -a -v -u '$DRY' --delete --exclude-from=.....'
			notify-send -t 2000 -h int:x:655 -h int:y:10 "SYSHALT with RSYNC" &
			$RSYNC_DAT
			SUCCDAT=$?
			$RSYNC_HOME
			SUCCHOME=$?
			if [ "$SUCCDAT" -eq "0" -a "$SUCCHOME" -eq "0" ] ; then
    			notify-send -t 2000 -h int:x:655 -h int:y:10 "RSYNC OK"
			else
	    		notify-send -t 2000 -h int:x:655 -h int:y:10 "RSYNC NOT OK , EXIT" &
       exit 1
			fi
	   ...continuing shutdown
Re: mit welchem Befehl Salix von der Konsole herunterfahren
Perhaps it would be better to run rsync on boot rather than shutdown?
In any case, to do it more robustly, yes, it would be good to have error handling, and also logging, since you don't envisage an interactive process (let alone a graphical front end). But then it gets rather complicated.
On the other hand, I believe rsync copes quite well with incomplete backups. So perhaps if your data is not really critical, there is no need to go to such lengths.
Es tut mir Leid, nicht auf Deutsch geschrieben zu haben ... fuer mich waere das auch eine gute Uebung gewesen.
			
			
									
						
										
						In any case, to do it more robustly, yes, it would be good to have error handling, and also logging, since you don't envisage an interactive process (let alone a graphical front end). But then it gets rather complicated.
On the other hand, I believe rsync copes quite well with incomplete backups. So perhaps if your data is not really critical, there is no need to go to such lengths.
Es tut mir Leid, nicht auf Deutsch geschrieben zu haben ... fuer mich waere das auch eine gute Uebung gewesen.