Hi,
I need a little help with this two scripts:
Gmail checker
Code:
#!/bin/bash
##
echo -e "Checking... \c"
atomlines=`wget -T 3 -t 1 -q --secure-protocol=TLSv1 \
--no-check-certificate \
--user=USER --password=PASSWORD \
https://mail.google.com/mail/feed/atom -O - \
| wc -l`
echo -e "\r\c"
[ $atomlines -gt "8" ] \
&& echo -e " Got mail. \c" \
|| echo -e " Nothing. \c"
Facebook wall poster
Code:
#!/bin/bash
email="EMAIL"
pass="PASS"
status="${@}" #must be less than 420 chars
if [ $(echo "${status}" | wc -c) -gt 420 ]; then
echo "FATAL: The status should not be longer than 420 characters!"
exit 1
fi
if [ -z "$status" ]; then
echo Usage: $0 '"My status update"'
exit 1
fi
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"`
if [ "$?" == "0" ]; then
echo "Status update successful!"
fi
rm "cookie.txt" #remove cookie file
I want to merge this two scripts into one, which will work like that:
From time to time script checks that is new mail in inbox then if there are some it login to facebook and posts message on GROUP wall.
Thanks for help I thought.
