Monday 7 March 2011

a simple perl timer scripts


hi

here is some simple code to shutdown the computer at a particular time.you probably may have more better script then this. or even write simple shell script. but here is what i use.


 $cont = "075500"; // time at which the computer must halt 07:55:00  
 $var = `date +%H%M%S`;//initializing the $var and getting the current time from the shell command and storing the value in $var  
 while(1)  
 {  
 if($var == $cont) //checking the values  
 {  
 `init 0`//signal command to shut down the computer.  
 `exit`  
 }  
 else  
 {  
 `sleep 1`;  
 $var = `date +%H%M%S`;//after every second getting the current time and matching the value in a infinite while loop.  
 }  
 }  

as halt command need super user privilege. you need to run the script as root or sudoer 

Thursday 3 March 2011

getting a mutual friend list using custom sql query in drupal

hi

i am using drupal UR module to implement the friends relations.below sql query is used to display mutual friend list. create custom module use this sql query and get the mutual friend list.


(SELECT user_relationships.rid AS rid, users_user_relationships.name AS users_user_relationships_name, users_user_relationships.uid AS users_user_relationships_uid, user_relationship_types_user_relationships.plural_name AS user_relationship_types_user_relationships_plural_name FROM user_relationships user_relationships LEFT JOIN users users_user_relationships ON user_relationships.requestee_id = users_user_relationships.uid LEFT JOIN users users_user_relationships_1 ON user_relationships.requester_id = users_user_relationships_1.uid LEFT JOIN user_relationship_types user_relationship_types_user_relationships ON user_relationships.rtid = user_relationship_types_user_relationships.rtid WHERE (user_relationships.approved = '$user->uid') AND (user_relationships.requester_id = arg(1)) OR (user_relationships.requester_id = build) GROUP BY users_user_relationships_uid HAVING count(*) = '2' ORDER BY user_relationship_types_user_relationships_plural_name ASC )