Registered Member
|
In this example we have 2 scripts.
I have not used this method to run the actual 1. completed-script.sh - this was the older method of notification.sh script where I held rcfile content as a shell script variable 2. pump-variables.sh - this script searchs config folder for a pattern of specific RC files (you can change this to your pattern of required RC files) and when it finds the files it types out files and takes aware lines and adds n to where lines are meant to be and generates two shell script variables. 1, filename=path to file 2. variable=content of file This may come in hand if you are tying to automate something and generating a script that you can use on any other KDE machine The current method of notification.sh relies on end user having those RC files , this method has all the required values automatically generated in a script ready to be used anywhere.. Pre -requists (replace.sh script) vi /usr/bin/replace.sh
chmod 755 /usr/bin/replace.sh This is now code for pump-variabe.sh (kept in ~/scripts/)
Here is the code for completed-script.sh have a look out of #insert_rc #inser_RM_here and #insert_variable this is where the pump variable after doing a search and parsing through the data will output actual variables.
Last edited by vahid on Sat Jul 04, 2009 11:49 am, edited 2 times in total.
|
Registered Member
|
RE: How to convert KDE RC files into variables for shell script (Automated script)
Wed Jun 24, 2009 8:56 am
Here is the result from me running it and after having one notifyrc file:
As you can see the completed-script.sh has new variables pumped in generated by pump-variable.sh nutter@muttley:~/scripts$ find ~/.kde/share/config/ -name *.notifyrc -print /home/nutter/.kde/share/config/powerdevil.notifyrc nutter@muttley:~/scripts$ ./pump-variables.sh rm: cannot remove `/home/nutter/scripts/workdir/*.notifyrc': No such file or directory The string has been replaced, if you have mucked up you will find the old file in /tmp/completed-script.sh nutter@muttley:~/scripts$ cat completed-script.sh #!/bin/sh user=`who -s|awk '{print $1" "$2}'|grep ":0"|awk '{print $1}'` home="/home/$user"; config="$home/.kde/share/config/" #insert_rc_path powerdevilnotifyrc=$config/powerdevil.notifyrc currentuser=`whoami` if [ $currentuser = "root" ]; then echo "error root can not run this, run as normal user"; exit; fi; case "${1}" in ("start") #insert_RM_here rm /home/nutter/.kde/share/config//powerdevil.notifyrc kill -9 `pgrep knotify4` echo "Ok Notifications for Powerdevil has now been re-enabled " ;; ("stop") #insert_variable ##########################start of powerdevilnotifyrc powerdevilnotifyrcc="[Event/criticalbattery] n Action= n Execute= n KTTS= n Logfile= n n [Event/doingjob] n Action= n Execute= n KTTS= n Logfile= n n [Event/inhibition] n Action= n Execute= n KTTS= n Logfile= n n [Event/joberror] n Action= n Execute= n KTTS= n Logfile= n n [Event/lowbattery] n Action= n Execute= n KTTS= n Logfile= n n [Event/pluggedin] n Action= n Execute= n KTTS= n Logfile= n n [Event/powerdevilerror] n Action= n Execute= n KTTS= n Logfile= n n [Event/profileset] n Action= n Execute= n KTTS= n Logfile= n n [Event/unplugged] n Action= n Execute= n KTTS=n Logfile= n n [Event/warningbattery] n Action= n Execute= n KTTS= n Logfile=" echo $powerdevilnotifyrcc > $powerdevilnotifyrc ##########################END OF powerdevilnotifyrc kill -9 `pgrep knotify4` echo "Ok Notifications for Powerdevil have now been stopped Danke " ;; (*) echo "$0 {start|stop}" exit ;; esac |
Registered users: Bing [Bot], Google [Bot], kesang, Sogou [Bot], Yahoo [Bot]