I would like to know how to make a script that I can run a bunch of commands using a variable then have it rerun with the next variable from a list of uid's one per line

This is so I can track who leaves Facebook or defriends me. I would like it to also track the same for any of my friends who want to know also. Hence a uid for each friend who wants my helpSomething like

Thanks for the help I got it to work. And just if anyone is interested in using it here is my more complete version with a lot of comments. I know some could be better but it works. The uids are kept one per line in a seperate text file. The only thing stopping this from being cronable is that I have to make sure I have a current Facebook session logged in to get lists from people who hide theirs.

Code:

#!/bin/bash

#Copies the cookies database to get around it being locked if anyone uses it must be changed to your file locationcp ~/.mozilla/firefox/gwatdpoo.SecondaryProfile/cookies.sqlite .

#Formats it so it can be diff'd#Makes each person have their own line since the default is one long linesed -i s/\{\"t\"\:/'\n'\{\"t\"\:/g $uid.new#Moves a little bit at the end to its own line to help the diff if something changes and they are not the end of the list anymoresed -i s/\]\,\"viewer/\,'\n'\]\,\"viewer/g $uid.new#Nothing to do with the script it just cleans up the urls so they can be copy and pasted to a browsersed -i 's/\\\//\//g' $uid.new#Adds a new line to the end of the file just to stop diff from complainingecho >> $uid.new

#Finds differences against old version and logs itdiff base/$uid.base $uid.new > log/$uid.log#I want to see what is happening as it happens so this shows the current uid then shows the saved logecho $uidcat log/$uid.log#Moves the log into storagemv log/$uid.log log/$uid."`date`".log

#Keeps copy then moves new version to the base that will be used next timecp $uid.new old/$uid."`date`"mv $uid.new base/$uid.basedone

The extractcookies script for no reason other then someone might like to use this method to track their friends list

Ok since I want to track a few people it is getting annoying to only refer to them by uid so if I was to modify the uids file to be some thing like this.

327457234 "John Doe"326832238 "Jane Doe"

How would I modify the "for uid in `cat uids`" to only use the uid and maybe have a separate $name variable with everything between the same lines "s so that I can echo it instead of the $uid when outputting the changes to the terminal and maybe depending on my mood use $name as part of the file names.

Well every time I get finished I eventually get bored and tweak it a little. and find new stuff I don't know how to do. Although this boredom has made it almost something that could be released and people could figure out easily. I have used more pipes to reduce file saves to the hard drive and cleaned up the friend list output.

My question now is when I use if to check for a directory or that the log has contents how can I check for not existing or if the the log is zero sized so that I can just use a then and not a else. Which leaves me with random crap in the then. This is worded badly but will be apparent if you look at the script.

Also any other suggestions to make this more professional looking.

Code:

#!/bin/bash

#Couple variables to editCOOKIEDIR=~/.mozilla/firefox/gwatdpoo.SecondaryProfileVERBOSE=yes#Default is numeric by uidSORTALPHA=no

#Note a valid session cookie is only needed to get friend lists for people who don't show it to everyone#Confirms it can make a fresh cookieecho "Have you made sure you are logged into Facebook"echo "Press enter to continue... "read

#Copies the cookies database to get around it being locked and attempts to find it if not properly told the locationif [[ -e $COOKIEDIR/cookies.sqlite ]] ; then cp $COOKIEDIR/cookies.sqlite . ; else cp `locate cookies.sqlite | head -n 1` . ; fi

#Formats it so it can be diff'd and easily read#Makes each person have their own line since the default is one long linesed s/\{\"t\"\:/'\n'/g | \#Nothing to do with the script it just cleans up the urls so they can be copy and pasted to a browsersed 's/\\\//\//g' | \#Cleanupsed s/\,\"i\"\:/'\t''\t'/g | \#More cleanupsed s/\,\"u\"\:\"/'\t'/g | \#Even more cleanupsed s/\"\,\"n\".*$// | \#Creates new file that only has people and not random info at beginning of filegrep facebook > "$name".new

#Finds differences against old version and logs itdiff base/"$name".base "$name".new > log/"$name"."$DATE".log

#I want to see what is happening as it happens so this shows log followed by some space to easily see where different people startif [[ $VERBOSE == yes ]] then echo $name cat log/"$name"."$DATE".log echo "" echo "" echo "" echo "" echo ""fi

#Moves the log into storage if it has contentsif [[ -s log/"$name"."$DATE".log ]] then nouse="justneededsomethingforthethen" else rm log/"$name"."$DATE".logfi

#Keeps copy then moves new version to the base that will be used next timecp "$name".new old/"$name"."$DATE"mv "$name".new base/"$name".basedone < uids

Ok I have been using this for awhile and need a workaround for some annoyances. If I leave the list in default uid order it randomly gets sent from Facebook out of order which cause false inserts and deletions when comparing with a list in the right order. If I sort it alphabetically it constantly changes because people constantly change their names for some reason. (respell their name, add or remove middle name or I have seen some young girls who just for fun hyphenate their last name with a celebrity's last name.)

How can I take my list which is in this format *note the names have " in the actual file"John Doe" (2 tabs) uid (1 tab) urland rearrange it touid (tab) "John Doe" (tab) url

Then I can sort based on uid which never changes and atleast get rid of the false deletions and insertions and have them properly show up as changes

I have tried 'curl' before, but this line seems to involve more than simply reading the 'html'.Where do you get the 'facebook' '$uid'?How do these "--user-agent" and "--cookie" options work?Your scripts sound exciting, and I want to try them, but I get nothing from this line.

The --user-agent is to fake being a web browser even though I don't use a full agent. Facebook requires one to prevent automatic downloading of files (even though it only fools the newest of users)

The --cookies loads a authenticated sessions credentials and is only needed for some people if they have their friend list hidden from non friends. Although it is impossible to block people from seeing your list if they know this url.

To find a users uid go to their profile and it will be in the url if they don't have a vanity url.example http://www.facebook.com/profile.php?id=3826483428If they use a vanity url I get their uid by viewing the filename of their profile picture it will be everything after the letter and before the _example n3826483428_5393.jpg

you save the uid and name in a external "uids" file using the following format note the ;'s2386423842;John Doe;8329164832;Jane Doe;

Here is my most up to date version of the script

Code:

#!/bin/bash

#Couple variables to editCOOKIEDIR=~/.mozilla/firefox/gwatdpoo.SecondaryProfile#Shows logs on terminal, recommended or you have to open each log individually.VERBOSE=yes

#Checks if needed directories exist and creates them if neededfor directory in base old log; do if [ ! -d $directory ]; then mkdir $directory; fidone

#Copies the cookies database to get around it being locked and attempts to find it if not properly told the locationif [[ -e $COOKIEDIR/cookies.sqlite ]] ; then cp $COOKIEDIR/cookies.sqlite . ; else cp `locate cookies.sqlite | head -n 1` . ; fi

#Formats it so it can be diff'd and easily read#Makes each person have their own line since the default is one long linesed s/\{\"t\"\:/'\n'/g "$name".fl | \#Nothing to do with the script it just cleans up the urls so they can be copy and pasted to a browsersed 's/\\\//\//g' | \#Cleanupsed s/\,\"i\"\:/'\t''\t'/g | \#More cleanupsed s/\,\"u\"\:\"/'\t'/g | \#Even more cleanupsed s/\"\,\"n\".*$// | \#Creates new file that only has people and not random info at beginning of filegrep facebook | \#Rearranges list for sorting incase Facebook sent any in the wrong order which prevents extra output from diffsed 's/\([^\t]*\)\t\t\([^\t]*\)\t\(.*\)/\2\t\1\t\3/' | \#Sorts the listsort -n > "$name".new

#Removes unformatted friend listrm "$name".fl

#Finds differences against old version and logs itdiff base/"$name".base "$name".new > log/"$name"."$DATE".log

#I want to see what is happening as it happens so this shows log followed by some space to easily see where different people startif [[ $VERBOSE == yes ]] then echo $name cat log/"$name"."$DATE".log echo "" echo "" echo "" echo "" echo ""fi

#Removes the log if it is emptyif [[ ! -s log/"$name"."$DATE".log ]] then rm log/"$name"."$DATE".logfi

#Keeps copy then moves new version to the base that will be used next timecp "$name".new old/"$name"."$DATE"mv "$name".new base/"$name".basedone < uids

When I use my own facebook uid in the curl command, before all the sed cleanup, I get returned a massive string with all my facebook friends listed.Listed along with the friends' names are the fields, '"i":iiiiiiiii', where "i" is given as a nine-digit number, presumably their facebook uids.

Thanks, darkshadow!

P.S. (to anyone who doesn't already know their facebook uid number), here is how to find it in the firefox (iceweasel) web-browser:

Main toolbar > Edit > Preferences > Privacy"Show Cookies" buttonIn the directory tree, open the folder "facebook.com", and highlight the item with cookie name, "c_user".This is the cookie containing your facebook uid, the contents will be displayed in the GUI window below.The content of this cookie is your facebook.com uid number ("c_user" number).(From here, if you follow along with darkshadow's script, you should be able to retrieve all the uids for the people on your facebook friends list.)

Last edited by gofree on Thu Feb 04, 2010 9:13 am, edited 1 time in total.

Who is online

Users browsing this forum: Google [Bot] and 1 guest

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum