Date command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date command
# 8  
Old 09-10-2012
This might be the cause of error... please check..

Code:
$ DATE3='TZ=GMT-168 $date +%y%m%d'
$ echo $DATE3
TZ=GMT-168 $date +%y%m%d

# 9  
Old 09-10-2012
Thankyou, getting somehwere now, just the DATE3 variable which isn't working correctly, I have the below now from what I understood from your reply. I need the date to be written into where the variable lies in the script e.g. 120910

Code:
 
#!/bin/bash
#A backup script if the default data file has not been sent over
#
EXTEN=.txt
VALID=VSL0120
DATE1=$(date +%y%m%d)
DATE2=000000
DATE3='TZ=TZ+168 $date +%y%m%d'
DIR=/apps/live/aahvanroutedata
#
if [ ! -e $DIR/VSL01_D* ]
#
then
        touch /export/home/tjmoore/default_data_backup_email < cat "We have not
        received todays default data file from Alliance, the default data file h
        as been used from the previous weeks same day"    
#
        cp $DIR/$VALID$DATE3$DATE2$EXTEN $DIR/$VALID$DATE1$DATE2$EXTEN 1 >>
        /export/home/tjmoore/default_data_backup_email
#
        /usr/local/bds/mailsend.s mailx "Backup Default Data File has been used"
        <email address> <email address> /export/home/tjmoore/de
        fault_data_backup_email > 2&1>/dev/null
#
fi

# 10  
Old 09-10-2012
you shoud re write it as below

Code:
DATE3='TZ=TZ+168 $date +%y%m%d'

To
Code:
 TZ=TZ+168
DATE3=`date +%y%m%d'`
TZ=TZ-168

just in case if you use date somewhere down below in the script.
# 11  
Old 09-10-2012
Doesnt seem to want to run the date command in between the TZ alterations

Just comes back with this if you echo it

Code:
 
date +%y%m%d'

If you run it like this however it does work but the the TZ changes dont apply

Code:
 
DATE=$(date +%y%m%d)

# 12  
Old 09-10-2012
hope this will give you a clear idea... I missed one single quote in the above command..

Code:
wload/lscp/home> date
Mon 10 Sep 16:29:20 2012
wload/lscp/home> TZ=TZ+168
wload/lscp/home> DATE3=`date +'%y%m%d'`
wload/lscp/home> TZ=TZ
wload/lscp/home> echo $DATE3
120903
wload/lscp/home> date
Mon 10 Sep 16:29:34 2012

# 13  
Old 09-10-2012
Quote:
Originally Posted by 02JayJay02
Code:
...
        /usr/local/bds/mailsend.s mailx "Backup Default Data File has been used"
        <email address> <email address> /export/home/tjmoore/de
        fault_data_backup_email > 2&1>/dev/null

should be:
Code:
        /usr/local/bds/mailsend.s mailx "Backup Default Data File has been used"
        <email address> <email address> /export/home/tjmoore/de
        fault_data_backup_email 2>&1 >/dev/null

IF you want STDERR to terminal, and STDOUT to /dev/null (as far as I know your code is not correct there).

And some line above you have 1 >> , I think it should be 1>> without space (or take away the "1", "1" (STDOUT) are default when using >>

One more thing, most people are not using "#" for empty lines, normally they are just empty, only a tip.
This User Gave Thanks to 244an For This Post:
# 14  
Old 09-11-2012
just wrote a seperate script as it seems to be just the date command thats not working now, I have the below but it doesnt output the date

Code:
#!/bin/bash
#
TZ=TZ+168
DATE='date +'%y%m%d''
TZ=TZ-168
#
echo $DATE

it just outputs

Code:
date +%y%m%d

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

awk command in hp UNIX subtract 30 days automatically from current date without date illegal option

current date command runs well awk -v t="$(date +%Y-%m-%d)" -F "'" '$1 < t' myname.dat subtract 30 days fails awk -v t="$(date --date="-30days" +%Y-%m-%d)" -F "'" '$1 < t' myname.dat awk command in hp unix subtract 30 days automatically from current date without date illegal option error... (20 Replies)
Discussion started by: kmarcus
20 Replies

2. HP-UX

HP/UX command to pull file name/date based on date

HI, Can anyone tell me how to pull the date and file name separated by a space using the find command or any other command. I want to look through several directories and based on a date timeframe (find -mtime -7), output the file name (without the path) and the date(in format mmddyyyy) to a... (2 Replies)
Discussion started by: lnemitz
2 Replies

3. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies

4. Shell Programming and Scripting

How to get tomorrow,yesterday date from date Command

Hi I want to get tomorrow and yesterday date from date command. My shell is KSH and server is AIX. I tried several options, but unable to do. Please help on this. Regards Rajesh (5 Replies)
Discussion started by: rajeshmepco
5 Replies

5. Shell Programming and Scripting

how to obtain date and day of the week from `date` command

Hi, does anybody know how to format `date` command correctly to return the day of the week? Thanks -A I work in ksh.... (1 Reply)
Discussion started by: aoussenko
1 Replies

6. Shell Programming and Scripting

date command

Hi is it possible to give the date command like 24th July 2009 ive tried DATE=`date "+%d%m%Y" echo $DATE that only replies 2009 correctly. not sure how to display the month in full or if unix knows how to do i.e 2nd, 24th, 3rd (1 Reply)
Discussion started by: magnia
1 Replies

7. UNIX for Dummies Questions & Answers

date command

Hi All. I'm using date -a to 'drift' the time forward / backwards. The question is - how do I know when its finished 'drifting' ? On some systems I have another time reference I can use but not always. thanks (1 Reply)
Discussion started by: Mudshark
1 Replies

8. Shell Programming and Scripting

want to get previous date from date command in ksh

I want to get previous date from date command. I am using ksh shell. Exmp: today is 2008.09.04 I want the result : 2008.09.03 Please help. Thanks in advance. (4 Replies)
Discussion started by: rinku
4 Replies

9. UNIX for Dummies Questions & Answers

Date Command

we're using HP-UX I need to change the year. What is the date command? Thanks (2 Replies)
Discussion started by: saldana
2 Replies

10. UNIX for Dummies Questions & Answers

date command

Using the date command how do get yesterday's date?? e.g. date '+%b%e%Y' July 30 2002 I need to get July 29 2002 using the date command. Thanx (p.s. sorry if it's a very obvious question) (6 Replies)
Discussion started by: niamo1
6 Replies
Login or Register to Ask a Question