나는 우분투 12.10을 통일로 운영하는 대학 실험실에 있으며 루트 특권이 없습니다. 로그 아웃 할 때 스크립트를 실행해야합니다. 이것이 가능한가?
참고 : 이것은 아마도이 질문 의 사본 일 것입니다. 그러나 주어진 대답은 매우 비밀스럽고 구체적인 지시는 없습니다.
답변
이것은 gnome_save_yourself
방법의 단계별 절차입니다 . 테스트를 해보자.
-
다음 코드를
~/Desktop/execute_script_on_shutdown.sh
( http://www.linuxquestions.org/questions/linux-desktop-74/gnome-run-script-on-logout-724453/#post3560301에서 ) 저장하십시오.#!/usr/bin/env python #Author: Seamus Phelan #This program runs a custom command/script just before gnome shuts #down. This is done the same way that gedit does it (listening for #the 'save-yourself' event). This is different to placing scipts #in /etc/rc#.d/ as the script will be run before gnome exits. #If the custom script/command fails with a non-zero return code, a #popup dialog box will appear offering the chance to cancel logout # #Usage: 1 - change the command in the 'subprocess.call' in # function 'session_save_yourself' below to be what ever # you want to run at logout. # 2 - Run this program at every gnome login (add via menu System # -> Preferences -> Session) # # import sys import subprocess import datetime import gnome import gnome.ui import gtk class Namespace: pass ns = Namespace() ns.dialog = None def main(): prog = gnome.init ("gnome_save_yourself", "1.0", gnome.libgnome_module_info_get(), sys.argv, []) client = gnome.ui.master_client() #set up call back for when 'logout'/'Shutdown' button pressed client.connect("save-yourself", session_save_yourself) client.connect("shutdown-cancelled", shutdown_cancelled) def session_save_yourself( *args): #Lets try to unmount all truecrypt volumes #execute shutdowwn script ######################################################################################### retcode = subprocess.call("bash /home/totti/Desktop/shutdown_script.sh", shell=True) ########################################################################################## if retcode != 0: #command failed show_error_dialog() return True def shutdown_cancelled( *args): if ns.dialog != None: ns.dialog.destroy() return True def show_error_dialog(): ns.dialog = gtk.Dialog("There was a problem running your pre-shutdown script", None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, ("There was a problem running your pre-shutdown script - continue logout", gtk.RESPONSE_ACCEPT)) if ns.test_mode == True: response = ns.dialog.run() ns.dialog.destroy() else: #when in shutdown mode gnome will only allow you to open a window using master_client().save_any_dialog() #It also adds the 'Cancel logout' button gnome.ui.master_client().save_any_dialog(ns.dialog) #Find out if we are in test mode??? if len(sys.argv) >=2 and sys.argv[1] == "test": ns.test_mode = True else: ns.test_mode = False if ns.test_mode == True: main() session_save_yourself() else: main() gtk.main()
-
그것을 실행 가능하게 만드십시오 :
chmod +x ~/Desktop/execute_script_on_shutdown.sh
-
다음을 다음과 같이 저장하십시오
~/Desktop/shutdown_script.sh
#!/usr/bin/bash touch ~/Desktop/AAAAAAAAAAAAAAAAAAAAAAAAAAA
-
메인 스크립트를 실행
bash ~/Desktop/execute_script_on_shutdown.sh
이제 스크립트가 무언가를 기다리는 느낌
- OS 로그 아웃 또는 종료 (우분투)
- 로그인
-
AAAAAAAAAAAAAAAAAAAAAAAAAAA
데스크탑에 이름이 지정된 파일을 확인하십시오 .ls -l ~/Desktop/AAAAAAAAAAAAAAAAAAAAAAAAAAA
파일이 보이면 모든 것이 정상입니다. 이제 shutdown_script.sh
필요에 맞게를 편집 할 수 있습니다 . 또한 execute_script_on_shutdown.sh
로그인시 실행해야합니다 (또는 시작시 자동으로 실행 가능하도록 설정).