Jump to content

Trying to make age calculator using bash script


NCC10281982B

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

  • 1 month later...

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...