Solved

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

Posted on 2013-06-26
1
352 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 39278191
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
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.:

726 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