Solved

Linux: Insert 1 hour old timestamp into wget found in .sh script

Posted on 2013-06-26
1
347 Views
Last Modified: 2013-06-26
I use the following code in a script called updatedb.sh to automatically update a database.

A crontab task is setup to run the script every hour.

Instead of using the hardcoded value of 1372258535 how can I get a timestamp value from one hour ago?

#### updatedb.sh ###
wget https://example.com/data.aspx?modified=1372258535 -q  --output-document /tmp/dataDump.txt
mysql -u DATABASE_USERNAME -pDATABASE_PASSWORD DATABASE_NAME  < /tmp/dataDump.txt
rm /tmp/dataDump.txt

Open in new window

0
Comment
Question by:hankknight
1 Comment
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
Comment Utility
1 hour ago from now?

TS=$(date -d "1 hour ago" "+%s")
echo $TS

#### updatedb.sh ###
wget https://example.com/data.aspx?modified=$(date -d "1 hour ago" "+%s") -q  --output-document /tmp/dataDump.txt
mysql -u DATABASE_USERNAME -pDATABASE_PASSWORD DATABASE_NAME  < /tmp/dataDump.txt
rm /tmp/dataDump.txt

Open in new window


or one hour ago from 1372258535 ?  ;-D

TS=$((1372258535-3600))
echo $TS

#### updatedb.sh ###
wget https://example.com/data.aspx?modified=$((1372258535-3600)) -q  --output-document /tmp/dataDump.txt
mysql -u DATABASE_USERNAME -pDATABASE_PASSWORD DATABASE_NAME  < /tmp/dataDump.txt
rm /tmp/dataDump.txt

Open in new window

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Utilizing an array to gracefully append to a list of EmailAddresses
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now