How do I get a date of yesterday in expect

How do I get a date of yesterday in expect



I write a expect script 1.sh:


#!/usr/bin/expect
set yest [exec `date -d "yesterday" '+%Y%m%d'`]
send_user $yest
exit 1



And run in linux ,use expect -d ./1.sh
But I get this error:


expect -d ./1.sh


expect version 5.44.1.15
executing commands from command file ./1.sh
invalid command name "/bin/date"
while executing
"date -d "yesterday" '+%Y%m%d'"
invoked from within
"set yest [date -d "yesterday" '+%Y%m%d']"



So,how do I fix this.I googled somethings and have no idea.
I find clock to instead date:


clock


date


https://www.tcl.tk/man/tcl8.5/TclCmd/clock.htm



And I get a way to run expect in bash:


#!/bin/bash
expect <<!
## expect code ##
!



Finally use this way to get yesterday string in expect script:


expect script


set yest [clock scan "yesterday"]
set yest1 [clock format $yest -format %Y%m%d]





Possible duplicate of invalid date error in the date command linux
– SolveProblem
Aug 27 at 6:57




2 Answers
2



Try this


#!/usr/bin/expect
set yest [ exec /bin/date -d "yesterday" +%Y%m%d]
send_user $yest
exit 1



Try out this way:



For yesterday :


date -d '-1 day' '+%Y%d%m'



For day before yesterday :


date -d '-2 day' '+%Y%d%m'





But I think the point of this error is : invalid command name "date", the commands date -d "yesterday" '+%Y%m%d' also worked fine in the linux
– code.g
Aug 27 at 6:45


invalid command name "date"


date -d "yesterday" '+%Y%m%d'





i m not clear with your question. If your code works fine then y are u getting error?
– SolveProblem
Aug 27 at 6:53






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

How do I collapse sections of code in Visual Studio Code for Windows?