?
Solved

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

Posted on 2013-06-26
1
Medium Priority
?
356 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 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month15 days, left to enroll

839 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