Jump to content
Sign in to follow this  
NCC10281982B

Trying to make age calculator using bash script

Recommended Posts

Greetings, I'm trying to create an image similar to

2015_02_18_21_05_10.jpg

for Facebook.

 

I am working with the following two scripts to accomplish this.

 

AGE CALCULATOR:

#!/bin/bash
TODAY=$(date +"%Y-%m-%d")
for (( ; ; ))
do
    clear
    read -p "May I know your name? " yourName
    read -p "Your birhdate (yyyy-mm-dd) ? " birthdate
        tmpDays=$( printf '%s' $(( $(date -u -d"$TODAY" +%s) - $(date -u -d"$bi$
    days=$(( $tmpDays / 60 / 60 / 24 ))
    hours=$(( $tmpDays / 60 / 60 ))
    mintues=$(( $tmpDays / 60 ))
    echo "You are $days days $hours hours $mintues mintues old"
    read -p "Try again (y/N) ? " tryAgain
    [ "$tryAgain" == "y" -o "$tryAgain" == "Y"  ] && : || break
done
 
IMAGE CREATOR:

#!/bin/bash
if [ "$1" = "--help" ] ; then
echo -e "Usage:\
Pipe some text into $0 with filename as an optional parameter."
exit 1
fi
if [ -n "$1" ] ; then
file="$1"
else
file="cli-"`date +%s`".png"
fi
echo "Saving to: $file"
echo "cli-"`date +%d`".png" | convert -weight bold  -background red  -fill blue$

The difficulty I have at the moment is the bash script generates a date that is 1+ days ahead of the phone app that created the image above. I think I can fix part of that by changing the timezone. Not sure though.

 

The image script is going to take the output from the age script.

 

I plan to use facebook command line to publish.

Share this post


Link to post
Share on other sites

Final running version. I figured it out.

#!/bin/bash
########################AGE CALCULATOR###############
#export TZ=PST
TODAY=$(date +"%Y-%m-%d")
todayx=$(date)
for (( ; ; ))
do
    clear
#    read -p "May I know your name? " yourName
#    read -p "Your birhdate (yyyy-mm-dd) ? " birthdate        
    birthdate=$((20150405))
tmpDays=$( printf '%s' $(( $(date -u -d"$TODAY" +%s) - $(date -u -d"$birthdate" +%s)))  ) 
    days=$(( $tmpDays / 60 / 60 / 24 ))
    hours=$(( $tmpDays / 60 / 60 ))
    mintues=$(( $tmpDays / 60 ))
    echo "You are $days days $hours hours $mintues mintues old"
echo $todayx
#read -p "Try again (y/N) ? " tryAgain
    [ "$tryAgain" == "y" -o "$tryAgain" == "Y"  ] && : || break
done
##########IMAGE CREATOR#########
if [ "$1" = "--help" ] ; then
echo -e "Usage:\
Pipe some text into $0 with filename as an optional parameter."
exit 1
fi
if [ -n "$1" ] ; then
file="$1"
else
file="/var/www/html/sober.png"
fi
echo "Saving to: $file"
echo -e  "Hello\n I am an alcoholic and\nI  been sober for\n $days days\n $hours hours\n$mintues Minutes" | convert -pointsize 36 -border 5 label:@- $file
#######DATE WATERMARK########
convert $file  -pointsize 12 \
          -draw "gravity south \
                 fill black  text 0,12 '$todayx' \
                 fill red  text 1,11 '$todayx'" \
         $file
####################FBCMD###########
/usr/local/bin/fbcmd addpic $file
#rm -rf $file

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...