For PHP version go here.
This is another example of “how to update Facebook status without any official API’s or apps” written in BASH (shell script). It is depending on the CURL program (which is included in most systems).
This bash script is also compatible with Mac OS X because of it’s unix-like architecture and because it includes the program “curl” (that is why i didn’t use “wget” this time). My script can currently log in, update status and log out. But there are plenty of things you could do in between, like updating pages, downloading photos, reading statuses, events… If you have a feature request post it in the comments. And if there is something you would improve, post that too!
Make sure that you:
- Enter a correct email and password,
- Have CURL with SSL support installed,
- Have read/write permissions in current directory.
- Run it with “bash” and not with “sh”.
- Download:fb-bot-bash
#!/bin/bash
#
# Facebook command line status update bot v1.0
# Author: Luka Pusic <pusic93@gmail.com>
# http://360percents.com/posts/bash-script-to-update-facebook-status-linux-mac-os-x/
#
email="email@domain.com"
pass="your_password"
status="yay :)" #must be less than 420 chars
touch "cookie.txt" #create a temp. cookie file
loginpage=`curl -s -c ./cookie.txt -A "Mozilla/5.0" "http://m.facebook.com"` #initial cookies
#LOGIN PARAMETERS
form_action=`echo "$loginpage" | tr '"' "\n" | grep "https://www.facebook.com/login.php"`
form_data=`echo "$loginpage" | sed -e 's/.*<form//' | sed -e 's/form>.*//' | tr '/>' "\n" | grep 'input ' | grep -v "email\|pass"`
#FUNCTION PARSES FORM DATA LIKE HIDDEN INPUTS
function parse_form() {
form_data="$1"
params=""
for (( i=1; i <= `echo "$form_data" | wc -l` ; i++ ))
do
name=`echo "$form_data" | sed -n "$i"p | tr ' ' "\n" | grep 'name' | cut -d '"' -f 2`
value=`echo "$form_data" | sed -n "$i"p | tr ' ' "\n" | grep 'value' | cut -d '"' -f 2`
params="$params$name=$value&"
done
echo "$params"
}
#LOGIN
params="email=$email&pass=$pass&"`parse_form "$form_data"`
logged_in=`curl -s -b ./cookie.txt -c ./cookie.txt -A "Mozilla/5.0" -d "$params" -L "$form_action"`
homepage=`curl -s -b ./cookie.txt -c ./cookie.txt -A "Mozilla/5.0" -L "http://m.facebook.com/profile.php"`
#UPDATE STATUS
status_form=`echo "$homepage" | sed -e 's/.*<form id="composer_form//' | sed -e 's/textarea>.*//' | tr '/>' "\n" | grep 'input ' | grep 'name' | grep -v 'query' | grep -v 'status'`
status_action=`echo "$homepage" | tr '"' "\n" | grep "/a/home.php?refid="`
status_params=`parse_form "$status_form"`"status=$status&update=Share"
update=`curl -s -b ./cookie.txt -c ./cookie.txt -A "Mozilla/5.0" -d "$status_params" -L "http://m.facebook.com$status_action"`
#$callback=`echo "$update" | grep "$status"` #just a primitive example of success checking
#LOGOUT
logout_link=`echo "$update" | tr '"' "\n" | grep "/logout.php?"`
logout=`curl -s -b ./cookie.txt -c ./cookie.txt -A "Mozilla/5.0" -L "http://m.facebook.com$logout_link"`
rm "cookie.txt" #remove cookie file











I posted another version of your script, I hope you don’t mind?
http://www.systmbx.com/scripts/bash-script-to-update-facebook-status-from-command-line
Btw, thanks for sharing it on systmbx.com.
It’s ok, i don’t mind :) I’m happy to see that people are working on it and improving it :)
Best regards
you are a wizard. i used your complex authentication thing and made the script download an entire fb photo album.
Thank you for this awesome script.
You can use command output instead of text, for example:
status=`df -h`
It will print the available disk space on your system.
:)
The script is fine (i think) but because my host is in a different country facebook gets moody and blocks my account.
Anyone else had this or has anyone worked out a way around this?
Try to login in via your server in this country with a browser and hopefully Facebook will add it to “trusted” hosts. Something like that :) Good luck
Hello,
I would like to use it for updating a page instead of the status of the profile. What do we need to adapt?
page = http://www.facebook.com/ijskafee
thanks,
Frank
Facebook just made page updating really complicated via Mobile platform, so i’m not sure how to do it at the moment…
fuck I spent 3 hours to ride a skript linke this and get it running before I just got the idear to google it.
by the way nice work
Well, that’s life :) Thank you!
Awesome script, thank you!
One minor change I made to the script was declaring the status variable like so:
status=”$@”
This basically allows me to declare my status in the shell by calling the script and typing my status update immediately after. That way, you don’t have to keep editing the script to declare your status variable.
Thanks again!
19: Syntax error: “(” unexpected
?
Just remove the parentheses.