Solved

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

Posted on 2013-06-26
1
348 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
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.

911 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

22 Experts available now in Live!

Get 1:1 Help Now