The Loser’s Script – How to wish facebook friends on their birthdays automagically in linux

Yes, It does what it tells it does. It may be one of the geekiest ways of wishing your friends on their birthdays. You won’t have to check every morning for people having birthdays, and go on writing on their walls. The script does it for you. And believe me, when you wish someone using a script for the first time, it feels terrible. You will start to see the fickleness, frailness of human relationships, freaks and fakes around us in a Web 2.0 world. But, if you dare to go forward and test it for yourself, scroll down to see the step-by-step instructions.

Step 1: Install cURL and Gnome-schedule

cURL is a command line tool for transferring data using various protocols. Gnome-schedule is a GUI for managing cron-jobs. Install them by running the famous command

sudo apt-get install curl gnome-schedule

Step 2: Setup a new application
Goto and setup a new application. Fill in all the required fields. Don’t forget to set ‘Application Type’ to ‘Desktop’. Remember the ‘Application ID’ and ‘Application secret’ given in the end of the process.

Step 3: Request an OAuth access token with the proper permissions
Facebook Graph API authorization documentation Has a detailed explanation about this. But if you are in a hurry,

  1. Enter the following URL in your browser, replacing YOUR_APPLICATION_ID with the application ID you got in the earlier step.,publish_stream,friends_birthday

  2. After a successful login and granting necessary permissions,  you will be given a verification code. Save it for later use.
  3. Enter the following URL in your browser, replacing YOUR_APPLICATION_ID with ‘Application ID’ and YOUR_API_SECRET with ‘Application secret’ you got earlier, and VERIFICATION_CODE with the code you got in the previous step.
  4. Now you will be given the precious ‘Access Token’. Save it somewhere

WARNING: Facebook does not recommend following this procedure and storing Access Tokens or Application secrets in desktop applications, because if somebody gets hold of that code, you are dead. I mean your facebook profile security is severely compromised and can be used in any malicious way they desire.

Step 4: Writing the script
No. Actually you just have to copy the following script I wrote and save it in a file like ‘/home/yourName/’ after  entering THE precious access token of yours in the proper place.


NOW=$(date +"%m/%d")

#Enter your access token below within quotations

#Get the names and UIDs of your unfortunate friends born on a day like today
curl "$ACCESS_TOKEN&query=SELECT%20first_name,uid%20from%20user%20where%20uid%20in%20(SELECT%20uid2%20from%20friend%20where%20uid1=564121985)AND%20substr(birthday_date,0,5)%20==%20'$NOW'" > birthdaywishtemp.xml

names=`sed -n -e 's/.*<first_name>\(.*\)<\/first_name>.*/\1/p' birthdaywishtemp.xml`
ids=`sed -n -e 's/.*<uid>\(.*\)<\/uid>.*/\1/p' birthdaywishtemp.xml`

F_ARRAY=( `echo ${names}` )
U_ARRAY=( `echo ${ids}` )

#Wish each of them with the same old boring message
for (( i = 0 ; i < ${#U_ARRAY[@]} ; i++ ))
curl '${U_ARRAY[$i]}'
curl -F 'access_token='$ACCESS_TOKEN'' \
    -F 'message=Hey, Happy Birthday...'${F_ARRAY[$i]} \${U_ARRAY[$i]}/feed >> birthdaywishbackup.log

#Let you know the progress
echo "Wished ${F_ARRAY[$i]}" >> birthdaywishbackup.log

echo "Completed on $(date)" >> birthdaywishbackup.log

Now you can browse to the location where you saved the script via terminal and execute the script with the command


And you can see the progress in the file birthdaywishbackup.log

Step 5: Automating the script
Yes, it is of no use if you have to run this manually each and everyday to wish somebody. So you can schedule it to run and write automagically on walls of birthday boys/gals everyday. If you are the geekiest type you can do it using a cron-job and you won’t need this tutorial anyway. But if you are interested, you can find how to do that here.
For the ordinary geek, there’s this dumb-simple GUI based tool called gnome-schedule. Run the command


in a terminal and you will be able to come up with a scheduled cron-job like the following in few easy steps.

IMPORTANT: Make sure you set a time of the day that you will keep your computer switched on, because a cron-job is not god, and doesn’t know how turn on the computer it is running, by itself 😀

It’s done!!! Enjoy being a lazy, cold-hearted nerd, who has no sense of finer things in life.

UPDATE: With all the controversial comments about this post here and in Reddit, I found an article written by another one who has thought on the same lines which totally explains my idea behind this script and blog post. Read and post your comments

It Was Your Birthday? Social Media Didn’t Tell Me That! by Jason Douglas

21 thoughts on “The Loser’s Script – How to wish facebook friends on their birthdays automagically in linux”

    1. Okay, pretty awesome.

      I am going to randomize the happy birthday wishes and set it up on a box that will never die.

      Unless you want people to wish USID 564121985’s friends happy birthday, which would be pretty funny actually, you need yo change this…

      I also changed the date selector to

      YESTERDAY=$(date -j -r $(( $(date -j -f “%a %b %d %T %Z %Y” “`date`” “+%s”) – 86400 )) +”%m/%d”)

      So I could send everyone a belated birthday instead. Because I think that is funnier.
      SELECT%20uid2%20from%20friend%20where%20uid1=564121985 to

  1. This is not really geeky, it’s just a waste of time.

    If you care about someone’s birthdays, you’ll have a calendar reminding you, and take some action that goes far beyond writing a card.

    If you don’t care, why sending a birthday card in the first place? That’d just generate birthday emails in return, to which you’d have adjust your spam scanner or a “thank you” auto-reply. I think every geek is able to perform the obvious optimization here: Don’t send birthday cards to people you don’t care in the first place.

    1. Yeah, Exactly.. That was the whole point of this article.. to remind what technology has brought to us. Rather than authentic bonding between humans, these tools make us cyborgs. Most of the time, relationships are freakishly artificial and limited to facebook walls. This was written in desperation to awaken everyone around me. Thanks for reading it and commenting by the way. Enjoy!!

  2. congratz , you also on Reddit . cool
    yeah actually to all my close friends i am call or sms to wish. even i dont feel it when i got a wish from fb. so its good that we hand over that to a app.

  3. Thanks for posting my blog on here. I received a lot of backlash privately for my experiment. I’m glad that you saw what I was trying to get out of it.


  4. Is it possible to implement this script for pc-users as well? I’m currently running Firefox with the Greasemonkey add-on.

  5. Good morning , sorry to my english.

    I can post status in the wall, but when use cron not work… Already try everything and cannot to use cron for automatize. Can be anything permission? if not use cron work!

    My code:

    api_client->session_key = FB_SESSION;

    $fetch = array(‘friends’ =>
    array(‘pattern’ => ‘.*’,
    ‘query’ => “select uid2 from friend where uid1={xxx}”));

    echo $facebook->api_client->admin_setAppProperties(array(‘preload_fql’ => json_encode($fetch)));

    $sql = $base ->query(‘SELECT * FROM wall WHERE DATE_FORMAT( data_agendada, “%H:%i” ) = DATE_FORMAT(“‘ . date(‘Y-m-d H:i:s’) . ‘”, “%H:%i”) ‘);

    while ($result = $base ->tupla($sql)) {

    echo $result [‘text_facebook’].””;

    echo “sign in”;

    if ($facebook->api_client->stream_publish($resultado[‘text_faceboon].” Testing cron”))
    echo “Added on test FB Wall”;
    } catch (Exception $e) {

    echo $e . “”;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s