Re: quick script question



M E Fieu wrote:
Hi.. Need to ask you a simple script question, I used the date command to get the yesterday web
log file using the following command echo ex`date -d yesterday +%y%m%d.log` in Linux. I want to
create a simple script to cat /home/IT/ex060530.log > kr.log using the following script but it is
not working. May I know how do I put the output of echo ex`date -d yesterday +%y%m%d.log into cat
/home/IT/xxxx > kr.log ?

[root@w2 krweblog3]# echo ex`date -d yesterday +%y%m%d.log`
ex060530.log

[root@w2 krweblog3]# vi krweblog.sh

#!/bin/sh
#
KRWEBLOG3= echo ex`date -d yesterday +%y%m%d.log`
cat /home/IT/$KRWEBLOG3 > kr.log

For thing like this, I like to use something like:

KRWEBLOG=$(date -d yesterday +ex%y%m%d.log)
cat /home/IT/$KRWEBLOG3 > kr.log

KRWEBLOG will have the value of ex060530.log if I ran it now on my
system. Enclosing a command inside $() returns the output of the
command. You could also use:
KRWEBLOG=`date -d yesterday +ex%y%m%d.log`
but I find the $() format easyer to read.

Mikkel
--

Do not meddle in the affairs of dragons,
for thou art crunchy and taste good with Ketchup!

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list



Relevant Pages

  • Re: Persisting env vars in cmd windows
    ... more about batch files as you go on, ... echo The time is %time::=.% ... But the piece de resistance was the "start" command, ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)
  • Re: Persisting env vars in cmd windows
    ... But the piece de resistance was the "start" command, ... - Have all code for the one project in one single batch file. ... @echo off ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)
  • Re: Persisting env vars in cmd windows
    ... even though it applies to any command, e.g. echo, copy, ... Similarly the syntax for the extremely powerful "for" command ... more about batch files as you go on, ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)
  • Re: Persisting env vars in cmd windows
    ... even though it applies to any command, e.g. echo, copy, ... Similarly the syntax for the extremely powerful "for" command ... more about batch files as you go on, ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)
  • Re: Persisting env vars in cmd windows
    ... I open several Command windows in succession. ... Drag the name of C000_CreateSymbols.bat into a new command window ... @echo off ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)