Jump to content


Photo
- - - - -

Trying to make age calculator using bash script


  • Please log in to reply
1 reply to this topic

#1 NCC10281982B

NCC10281982B

    The useless guy™

  • Moderator
  • PipPipPipPipPipPip
  • 6988 posts
  • Gender:Male
  • Location:Bellevue, WA

Posted 18 February 2015 - 09:25 PM

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.
I am DUMB, okay? Dumb as a post! Think I'm happy about it?
 
sigimage.gifCFr15LujaQwHZgiAc222zw.png

#2 NCC10281982B

NCC10281982B

    The useless guy™

  • Moderator
  • PipPipPipPipPipPip
  • 6988 posts
  • Gender:Male
  • Location:Bellevue, WA

Posted 16 April 2015 - 02:16 PM

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


I am DUMB, okay? Dumb as a post! Think I'm happy about it?
 
sigimage.gifCFr15LujaQwHZgiAc222zw.png